S
sam
Hi,
I would like to write a perl script to parse each line read from a text
file.
I ended up some perl code as shown below:
($prodcode,$custname,$qty,$cost,$date,$prodname) =
/^([0-9\-]+) +([A-Za-z0-9\-]+) +([0-9]+\.[0-9][0-9])
+([0-9]+\.[0-9][0-9])([0-9]+)(.*)/,
"12031361 ABC3 567.00
5177.6620041127\xbd\xba\xa6w\xc5@\xb9\xea\xb4f\xc5\xd6\xa5\xa9(\xacX\xb2n\xb4\xd6\
xbch)\xa4\xe9\xa5\xce12x20's";
print "Result:
".$prodcode.",".$custname.",".$qty.",".$cost.",".$date.",".$prodname . "\n";
if ($prodcode eq "" or $custname eq "" or $qty eq "" or $cost eq "" or
$date eq "" or $prodname eq "") {
print "Failed to parse input file.\n";
exit;
}
But the parser failed to parse the input text, it returns empty string.
What is wrong with the above code, especially the parser I created for
parsing the $date.
Thanks
Sam
I would like to write a perl script to parse each line read from a text
file.
I ended up some perl code as shown below:
($prodcode,$custname,$qty,$cost,$date,$prodname) =
/^([0-9\-]+) +([A-Za-z0-9\-]+) +([0-9]+\.[0-9][0-9])
+([0-9]+\.[0-9][0-9])([0-9]+)(.*)/,
"12031361 ABC3 567.00
5177.6620041127\xbd\xba\xa6w\xc5@\xb9\xea\xb4f\xc5\xd6\xa5\xa9(\xacX\xb2n\xb4\xd6\
xbch)\xa4\xe9\xa5\xce12x20's";
print "Result:
".$prodcode.",".$custname.",".$qty.",".$cost.",".$date.",".$prodname . "\n";
if ($prodcode eq "" or $custname eq "" or $qty eq "" or $cost eq "" or
$date eq "" or $prodname eq "") {
print "Failed to parse input file.\n";
exit;
}
But the parser failed to parse the input text, it returns empty string.
What is wrong with the above code, especially the parser I created for
parsing the $date.
Thanks
Sam