I using ActiveState Perl version 5.8.4.810 and got an ASCII file with different length and format records, some of these fields with other languages edit chars, also widly used characters in PERL, (ie $).
How can I do this, also if using unpack, as well as, implications by using this script via CGI?
The test data file:
C~1212|Jan|Jaspree|Painter|38|$100,500.50
C~3453|Kelly|Horton|Jockey|27|$110,250.30
N~4312|Mario|Galvan|$100,100.40
N~3912|Tom|Cat|$10,345.10
N~1010|Micky|Mouse|$12.50
This following script set the wrong values for the scalar variables.
I appreciate your support!use Sed; open(FILE, "<fields01.dat"); while(<FILE>) { $_ = sed { s/\$//g } $_; $_ = sed { s/,//g } $_; ($rectype, $_) = split(/\~/, $_); printf("%s : %s\n", $rectype, $_); if ($rectype == "C") { ($empno, $fName, $lName, $job, $age, $salary) = split(/\|/, $_ +,6); printf("Employee NO:%s Name:%s FamilyN:%s Job:%s Age:%d Salary +:%10.2f\n", $empno, $fName, $lName, $job, $age, $salary); } else { ($empno, $fName, $lName, $salary) = split(/\|/, $_,4); printf("Employee NO:%s Name:%s FamilyN:%s Salary:%10.2f\n", $empno, $fName, $lName, $salary); } } close(FILE);
In reply to Reading different format records from an ASCII file by felipon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |