Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem reading file in while loop

Status
Not open for further replies.

jowatkins

Technical User
Apr 30, 2003
1
GB
hi,

I'm a complete newbie at perl and was hoping somebody might be able to help me a problem I'm having.
Here is the code:

sub get_partnumber
{
my ($file, $ref) = @_;
my $pn;
print "$ref\t";
while (<$file>)
{
print &quot;$ref\n&quot;;
if ($_ =~ /$ref/)
{
/([0-9]{9}|T[0-9]{8})/; #get the part number
$pn= $1;
}
else
{
$pn = 0;
}
}
return $pn;
}

I thought at first that this is a scope problem, and that the $ref variable wasn't available within the while loop. However, itseems that the code isn't going into the while loop at all. I can't think of any reason for this. Can somebody suggest a way to fix it?

Thanks in advance, Jo








 
How are you calling the subroutine? Is $file the name of a file or a filehandle? If its the name of a file then you have to open the file first and loop over the filehandle.

jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top