rbc has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; my @names; my @items; sub processRec { my $fh = shift; #ref to filehandle while(<$fh>) { chomp; s/\cM//; last if /^$/; last if /^\d-RECORD$/; push ( @names, /ITEMNAME-(.*)/); push ( @items, /ITEM \d-(.*)/); } } open( FH, "<data"); while(<FH>) { if ( /\d-RECORD/ ) { processRec(*FH); } } close(FH); for my $name ( @names ) { print "name = [$name]\n"; } for my $item ( @items ) { print "item = [$item]\n"; }
$ cat data 1-RECORD ITEMNAME-bob ITEM 1-socks ITEM 2-shoes 2-RECORD ITEMNAME-bill ITEM 1-hat ITEM 2-hair piece 3-RECORD ITEMNAME-mary ITEM 1-roach clip 4-RECORD ITEMNAME-jimmy ITEM 1-peanuts ITEM 2-tooth pick
name = bob name = bill name = jimmy item = socks item = shoes item = hat item = hair piece item = peanuts item = tooth pick
sub processRec {
...
if (/^\d-RECORD$/) {
put_line_back ($_);
last;
};
...
}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I re-read a line?
by Mr. Muskrat (Canon) on May 01, 2002 at 21:54 UTC | |
by rbc (Curate) on May 01, 2002 at 22:00 UTC | |
|
Re: How do I re-read a line?
by Kanji (Parson) on May 01, 2002 at 21:58 UTC | |
|
(jeffa) Re: How do I re-read a line?
by jeffa (Bishop) on May 01, 2002 at 22:23 UTC | |
by belg4mit (Prior) on May 01, 2002 at 22:42 UTC | |
|
Re: How do I re-read a line?
by Dog and Pony (Priest) on May 01, 2002 at 21:57 UTC |