By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,301 Members | 1,752 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,301 IT Pros & Developers. It's quick & easy.

Extracting records

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.