quasimojo has asked for the wisdom of the Perl Monks concerning the following question:
If I have a file in which I am searching for any line beginning with "Open Square Bracket" and ending with "Close Square Bracket" and then saving all such matching lines in an Array called @BROKERS. How would I tell perl to go through the file again, matching on each element of @Brokers, and then after it found a line that matched that element push each subsidiary line that followed into an array named $BROKER[x] until a blank line is reached. At this point the loop should continue to the next element of @BROKERS and repeat the above proccess until there are no elements left.
I am very new to perl and languages in general so please excusive the crudity of the code I have written so far.
#!/usr/bin/perl -w # my @BROKERS; open (CONFIG, "ubroker.properties") || die "Can't Open ubroker file: $ +!"; while (<CONFIG>) { next if /^#/; if (/^\[UBroker\.WS\./) { push (@BROKERS,$_); } } chomp @BROKERS; while (<CONFIG>) { foreach $b(@BROKERS) { if (/$b/) { # Here is where I run out of steam # Begin Metacode read each line and push ($_,@"$b") continue to do this until + a newline is reached. When a newline is reached intialize the next +$b as an array and repeat the above proccess until all elements of @B +ROKERS are exhausted.
Edit by tye
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Appropriate application of readline
by blakem (Monsignor) on Sep 26, 2001 at 23:34 UTC | |
by quasimojo (Initiate) on Sep 27, 2001 at 18:30 UTC | |
|
Re: Appropriate application of readline
by tachyon (Chancellor) on Sep 26, 2001 at 23:14 UTC |