[EMAIL PROTECTED] wrote: >> open (FH, './fai.txt') || die "Cannot open file: ($!)"; >> my @parts = <FH>; >> my @rev = <FH>; > > This stores two copies of the file in memory, do you need two copies? >
It doesn't actually. The first assignment leaves you at end-of-file so subsequent reads fail. @parts will contain all of the file records and @rev will be empty. Also need to chomp @parts, otherwise the last field will have a trailing "\n". And @parts is a misconception - should be @records or something. >> foreach my $line (@parts, @rev) { > > This (I believe) is going to combine @parts and @rev so you will step > through the file twice. Are you expecting alternating lines in the > file? Yes and no, in that order! @rev is empty as I said, so this is the same as while (my $line = <FH>) { without the above array reads. This is the preferable way to do it, although it's probably worth declaring our @lines = <FH> unless @lines; chomp @lines; to keep a persistent copy of the file for multiple calls to the routine. (But let's get it working first :) > >> my @fields = split(/\|/, $line); >> if ($args{part} eq $fields[0], $fields[1]) { > > if (($args{'part'} eq $fields[0]) && ($args{'rev'} eq $fields[1])) { (No need for quotes or internal parentheses, for what it's worth) > >> $retval = \@fields; >> last; It's more concise if you just close the file and 'return' out of the loop at this level: close FH; return \@fields; >> } >> } >> close FH; >> return $retval; Just: return undef; >> } I hope that's fairly clear. It's getting a bit of a mess :-/ Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]