in reply to Re^2: Splitting file into separate files based on record lengths and identifiers
in thread Splitting file into separate files based on record lengths and identifiers
Update .. got this far, but it just spits out the same data over and over again so I've not got the while loop quite right, any ideas?
#!/usr/bin/perl use strict; use warnings; my $string = '0004$ADAM0002*330005LTESTL0005STESTS0005JTESTJ0005ZTESTZ +'; my $currentpos = 0; while ($string) { my $recordlength = (substr $string, $currentpos, 4)+5; my $recordtype = substr $string, $currentpos+4, 1; my $fragment = substr $string, $currentpos+5, $recordlength-5; my $nextstartpos = $recordlength+1; print " string: $string\n"; print " record type: $recordtype\n"; print " data: $fragment\n"; print " tot record length: $recordlength\n"; print " next start pos: $nextstartpos\n"; my $currentpos = $currentpos + $recordlength+1 }
Thanks!
|
|---|