in reply to Appropriate application of readline

It seems like you should be using a slightly different datastructure for this. A hash of arrays (HoA) would fit nicely... The hash is keyed on the broker's name and the values are arrays containing the matching lines. Something like this:
#!/usr/bin/perl -wT use strict; my @brokerlist = qw(broknum1 broknum2 broknum3); # array of brokers my $pattern = join('|',@brokerlist); # create a ORed regex of the b +rokers my %brokers; # will become a hash of arrays, keyed on broker nam +e while(<DATA>) { chomp; # if the line matches push it onto appropriate array push(@{$brokers{$1}},$_ ) if /\b($pattern)\b/o; } ### print out the datastructure to make sure it is correct for my $broker (keys %brokers) { print "$broker\n"; print "\t$_\n" for (@{$brokers{$broker}}); } =OUTPUT broknum2 broknum2 is my favorite broker broknum3 i am a broknum3 client my uncle is broknum3 broknum1 this line if for broknum1 broknum1 is a fool =cut __DATA__ this line if for broknum1 i am a broknum3 client broknum2 is my favorite broker broknum1 is a fool my uncle is broknum3

-Blake

Replies are listed 'Best First'.
Re: Re: Appropriate application of readline
by quasimojo (Initiate) on Sep 27, 2001 at 18:30 UTC
    Thanks for the reply's everbody!!!
    While I was waiting for some answers I decided to forge on by myself. Obviously the ideas you guys gave me are better, and I will be incorporating them into my current code. For posterity though here is how I worked around:
    #!/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; @FIRST=split(/\s+/,$BROKERS[1]); #@SECOND=split(/\s+/,$BROKERS[2]); #@THIRD=split(/\s+/,$BROKERS[3]); #@FOURTH=split(/\s+/,$BROKERS[4]);; foreach $i(@FIRST) { if ($i =~ /^initialSrvrInstance/i) { $max= $i; print "$max\n"; } } close (CONFIG) || die "Can't Close ubroker file: $!"; exit 0;

    But like you said I really like the entire hash approach better then what I am doing now!!!
    Thanks for the Help!
    Pat+