P
PugetSoundSylvia
Hello all,
I'm just starting to get into perl, so please forgive me if I'm asking
something obvious.
I'm using the unpack function to parse through a fixed length file.
It's working well, but there's lots and lots of fields, and I'd like
to make the code more readable.
What I have now is this:
$LOGFILE = "text.log";
open(LOGFILE) or die("Could not open log file.");
# Define the record format for unpack function
$BaseBSPFileTemplate =
"A3" # RecordType Field 0
."A8" # SequenceNumber Field 1
."A2" # RecordTypeSuffix Field 2
."A6" # CreateDate Field 3
."A6" # TransactionNumber Field 4
."A15" # DataNumber Field 5
."A98" # UpdateDate Field 6
;
while (<LOGFILE>) {
@fields = unpack( $BaseBSPFileTemplate, $_ );
$RecordType = $fields[0];
$SequenceNumber = $fields[1];
$RecordTypeSuffix = $fields[2];
... and so forth ...
Is there a better way to do this - one where the unpack function
itself would automatically split it into the actual variables
($RecordType, $SequenceNumber, $RecordTypeSuffix, etc) - instead of me
having to have the section that has a bunch of rows like this:
$RecordType = $fields[0];
Thanks much for any advice!!
Sylvia
I'm just starting to get into perl, so please forgive me if I'm asking
something obvious.
I'm using the unpack function to parse through a fixed length file.
It's working well, but there's lots and lots of fields, and I'd like
to make the code more readable.
What I have now is this:
$LOGFILE = "text.log";
open(LOGFILE) or die("Could not open log file.");
# Define the record format for unpack function
$BaseBSPFileTemplate =
"A3" # RecordType Field 0
."A8" # SequenceNumber Field 1
."A2" # RecordTypeSuffix Field 2
."A6" # CreateDate Field 3
."A6" # TransactionNumber Field 4
."A15" # DataNumber Field 5
."A98" # UpdateDate Field 6
;
while (<LOGFILE>) {
@fields = unpack( $BaseBSPFileTemplate, $_ );
$RecordType = $fields[0];
$SequenceNumber = $fields[1];
$RecordTypeSuffix = $fields[2];
... and so forth ...
Is there a better way to do this - one where the unpack function
itself would automatically split it into the actual variables
($RecordType, $SequenceNumber, $RecordTypeSuffix, etc) - instead of me
having to have the section that has a bunch of rows like this:
$RecordType = $fields[0];
Thanks much for any advice!!
Sylvia