in reply to pulling information from a delineated text file using a subroutine
#!/usr/bin/perl -w use strict; sub get_part_num { my $part; while (!$part || $part =~ /[^0-9]/) { print "Part Number? "; chomp( $part = <STDIN> ); } return $part; } sub search { my ($file, $part) = @_; open my $db, "<$file" or die "Could not read file: $!"; while (<$db>) { chomp; my @fields = split(/\|/, $_); print "Part $part found: \n\t", join("\n\t", @fields[1..$#fields]), "\n" if $fields[0] eq $part; } } search( 'fai.txt', get_part_num() );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: pulling information from a delineated text file using a subroutine
by Hofmator (Curate) on Jan 16, 2003 at 10:00 UTC | |
by Coruscate (Sexton) on Jan 17, 2003 at 00:24 UTC |