in reply to pulling information from a delineated text file using a subroutine

Another solution, hopefully easy to understand.
sub find_matching_part_entry { my( $filename, $part, $rev ) = @_; open F, "< $filename" or die "Error reading $filename: $!\n"; my @match; while (<F>) { chomp; my @fields = split /\|/; if ( $fields[0] eq $part && $fields[1] eq $rev ) { @match = @fields; } } close F; return @match; } my @matching_entry = find_matching_part_entry( "fai.txt", $part, $rev +); if ( @matching_entry ) { print "Found part:\n"; for ( @matching_entry ) { print "$_\n"; } } else { print "No part matching $part, rev $rev found!\n"; }
Note - No global variables.

jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.

  • Comment on Re: pulling information from a delineated text file using a subroutine
  • Download Code