Here's a simple method that doesn't require you to know what tags are in each section, or even what order the tags you are interested in appear. It is also easily extended to handle more tags of interest. The output is an array of hashes:
#! perl -slw
use strict;
use Data::Dump qw[ pp ];
my @accts;
{
local $/ = 'TAGEND';
while( <DATA> ) {
m[
(?=.* FIRSTNAME \s+ ( \S+ ) )
(?=.* LASTNAME \s+ ( \S+ ) )
(?=.* ACCOUNT \s+ ( \S+ ) )
(?=.* BILLAMOUNT \s+ ( \S+ ) )
]xsm and push @accts, {
firstname => $1,
lastname => $2,
account => $3,
billamount => $4,
};
}
}
pp \@accts;
__DATA__
And the output: C:\test>junk47.pl
[
{
account => 1000901,
billamount => 4200,
firstname => "DAVID",
lastname => "RHODES",
},
{
account => 1000902,
billamount => 10000,
firstname => "MARY",
lastname => "RHODES",
},
{
account => 1000903,
billamount => 1200,
firstname => "BILL",
lastname => "HICKOK",
},
{
account => 1000909,
billamount => -1,
firstname => "FRED",
lastname => "BLOGGS",
},
]
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|