in reply to Re: Re: Missing the if statement and going directly to else
in thread Missing the if statement and going directly to else
This search routine returns 1 if it found a match, undef otherwise. You can put this in a routine which asks for input, like this:sub search { my ($PartNumber) = @_; while (<FILE>) { if ($main::fields[0] eq $PartNumber) { # ... return 1; # Ends search() function } } close(FILE); return; # Returns empty handed }
This loop will continue to run until the search() function returns a true value. That will only happen if a match is found.$|++; my $what; do { print "PartNumber? "; chomp($what = <STDIN>); } while (!search($what));
|
|---|