Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Extracting records

Reply
Thread Tools

Extracting records

 
 
Dj Frenzy
Guest
Posts: n/a
 
      12-02-2003
Hi, I am looking for a solution to this problem. I receive a list of
records like this, in one continuous string. I want to separate each
record and extract some of the data for each record. The records look
like this:

(=YEAR:1991;month:[JAN]client-NAME:[Ali-Baba-Basket-Emporium]AREA:[SouthEast]value:[1905]=)(=YEAR:1997;month:[dec]client-NAME:[Fletcher]AREA:[Scotland(North)]discount:[7%]value:[741]=)(=YEAR:2003;month:[MAR]client-NAME:[Porridge-dot-com]AREA:[N.Ireland]discount:[7%]value:[335]=)

For example, in this record:
(=YEAR:2003;month:[MAR]client-NAME:[Porridge-dot-com]AREA:[N.Ireland]discount:[7%]value:[335]=)

I want to extract the year: "2003"
month: "MAR"
clientName: "Porridge-dot-com"
area: "N.Ireland"
discount (which is an optional field): "7"
value: 335.

An help in how to do this would be appreciated.
Cheers,
Dave
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      12-02-2003
Dj Frenzy wrote:
> I receive a list of records like this, in one continuous string. I
> want to separate each record and extract some of the data for each
> record. The records look like this:
>
> (=YEAR:1991;month:[JAN]client-NAME:[Ali-Baba-Basket-Emporium]AREA:[SouthEast]value:[1905]=)(=YEAR:1997;month:[dec]client-NAME:[Fletcher]AREA:[Scotland(North)]discount:[7%]value:[741]=)(=YEAR:2003;month:[MAR]client-NAME:[Porridge-dot-com]AREA:[N.Ireland]discount:[7%]value:[335]=)
>
> For example, in this record:
> (=YEAR:2003;month:[MAR]client-NAME:[Porridge-dot-com]AREA:[N.Ireland]discount:[7%]value:[335]=)
>
> I want to extract the year: "2003"
> month: "MAR"
> clientName: "Porridge-dot-com"
> area: "N.Ireland"
> discount (which is an optional field): "7"
> value: 335.


How about:

my @records;

for (split /\)\(/) {

if (/(\d+) # year
[^\[]+\[
([^\]]+) # month
[^\[]+\[
([^\]]+) # clientName
[^\[]+\[
([^\]]+) # area
(?:
\]discount:\[
(\d+) # discount
)?
[^\[]+\[\D?
(\d+) # value
/x) {

push @records, {
year => $1,
month => $2,
clientName => $3,
area => $4,
discount => ($5 or 0),
value => $6,
}
}
}

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple query returns 0 records in asp, but all records in vbscript masg0013@gmail.com ASP General 3 11-02-2006 09:23 AM
extracting text from files using IFilters kunal ASP .Net 0 10-15-2005 11:09 AM
extracting records from a file Aleander C++ 2 05-30-2005 11:34 AM
Delete records or update records Dan ASP General 1 05-10-2004 01:25 PM
match muliple header records to associated detail records Luke Airig XML 0 12-31-2003 12:06 AM



Advertisments