Amongst other things, the following line is in error and will cause your script to fail:
open(FILE, '>>fai.txt') || die $!;
The >> cause the file to be opened in "append" mode. You want "read" mode. You can do this to correct this:
sub search { my ($file,$part_number,$revision) = @_; open FILE "< $file" or die "Cannot open ($file) for reading: $ +!"; local $_; while (<FILE>) { # search line for $part_number
Note that I have have made some changes. First, I have explicitly passed the necessary arguments to the subroutine. This makes it easier to reuse or move to a library, if necessary. Further, I've localized $_. This restricts changes to $_ to the current scope, thus ensuring that if another part of your program uses $_, you won't accidentally have a strange value in there. See perldoc -f local for more information on this.
Cheers,
Ovid
New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)
In reply to Re: pulling information from a delineated text file using a subroutine
by Ovid
in thread pulling information from a delineated text file using a subroutine
by Bismark
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |