JPaul has asked for the wisdom of the Perl Monks concerning the following question:
There has to be a nicer way! :)my $section = 0; my @sectone; my @secttwo; while(<TEXTFILE>) { if (/;section1/) { $section = 1; } elsif (/;section2/) { $section = 2; } else { if ($section == 1) { push(@sectionone, $_); } elsif ($section == 2) { push(@sectiontwo, $_); } else { print "No section defined for: $_\n"; } } }
JP,
-- Alexander Widdlemouse undid his bellybutton and his bum dropped off --
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tidier and more efficient parsing code
by Fletch (Bishop) on Jan 24, 2002 at 08:58 UTC | |
by JPaul (Hermit) on Jan 24, 2002 at 21:49 UTC | |
|
(crazyinsomniac) Re: Tidier and more efficient parsing code
by crazyinsomniac (Prior) on Jan 24, 2002 at 09:05 UTC | |
by demerphq (Chancellor) on Jan 24, 2002 at 15:19 UTC | |
|
Re: Tidier and more efficient parsing code
by demerphq (Chancellor) on Jan 24, 2002 at 15:06 UTC | |
|
Re: Tidier and more efficient parsing code
by flocto (Pilgrim) on Jan 25, 2002 at 18:41 UTC | |
|
Re: Tidier and more efficient parsing code
by lirm (Novice) on Jan 26, 2002 at 00:05 UTC | |
by particle (Vicar) on Jan 26, 2002 at 00:10 UTC |