in reply to while statement only picks up first line

erm - I'm not sure you want to use shift where you do - If you've only one item in the array then by the time you come to the second pass you've emptied the array and your results will be awry.

Update: Sorry -had to dash away...

while (@partners){ my $item = shift (@partners); while (<FH>) { my ($usernamedb,$surname,$firstname,$secondname)=split (/\t/,$_); if ($item eq $usernamedb) { print qq{$firstname $secondname $surname}; } } }
But this may not be very efficient...

Replies are listed 'Best First'.
Re: Re: while statement only picks up first line
by graff (Chancellor) on Feb 06, 2004 at 04:27 UTC
    Um... lack of efficiency, for sure, but that's the lesser problem in this case. Your approach would involve re-reading the entire input file for each element in @partners, which is bad enough, but then you forgot to "seek FH, 0, 0" after (or before) the embedded while loop that reads the file, so there would be nothing left to read when looking for the second element in @partners.

    Doing "grep ..., @partners" for every line of the input file (as suggested in an earlier reply) is also a bit short on efficiency, if @partners has a lot of elements. Based on what the OP seems to be trying to do, a hash would be better than an array:

    ... print ... if ( exists( $partners{$usernamedb} ));