I'm almost positive that I didn't write it exactly like that because I almost never write not as an exclamation mark. Anyhow, you could omit that $found value because your last skips right out of the while. The other use you use for $found is irritating. I much prefer setting the return value explicitly and letting that take the place of $found. I copied my code, fixed it up and commented the changes.
sub search { my %args = @_; # Turned into a scalar. An array reference will be # stored here if the value being searched for was # found. my $return_record; local *PARTS_DB; open PARTS_DB, $args{filename} or die "Cannot open file $args{fil +ename}: $!"; while (my $record = <PARTS_DB>) { chomp $record; my @record = split /\|/, $record; next unless $record[PART] eq $args{part} and $record[REV] eq $args{rev}; # Change this from assigning to @return_record # so now it's an array reference. Also add a last; # call; $return_record = \ @record; last; } close PARTS_DB or die "Can't close PARTS_DB $args{filename}: $!"; # This returns whatever was found which may be nothing return $return_record; }
Seeking Green geeks in Minnesota
In reply to Re^3: using join with a print ref statement
by diotalevi
in thread using join with a print ref statement
by Bismark
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |