in reply to Re: Splitting file into separate files based on record lengths and identifiers
in thread Splitting file into separate files based on record lengths and identifiers
Morning all!
While I massively appreciate the scripts here I just feel like I'm not learning anything, which is not good for anybody :) I have in my head the logic (probably flawed at this stage) I want to use and I've started from scratch on something really simple so perhaps people could help me go down that path?
#!/usr/bin/perl use strict; use warnings; my $string = '0004$ADAM0002*330005LTESTL0005STESTS0005JTESTJ0005ZTESTZ +'; my $len1 = substr $string, 0, 4; my $type = substr $string, $len1, 1; my $fragment = substr $string, $len1+1, $len1; my $nextpos = $len1+5; print " string: $string\n"; print " 1st data length: $len1\n"; print " data: $fragment\n"; print " type: $type\n"; print " next record lenth pos: $nextpos\n";
string: 0004$ADAM0002*330005LTESTL0005STESTS0005JTESTJ0005ZTESTZ 1st data length: 0004 data: ADAM type: $ next record lenth pos: 9
The way I'd like to approach this is to start at beginning of the line and use the length string in each case to extract the string. So in the example above I use the '0004' to identify the data in the first field and then to identify where the next length marker for record 2 begins
What I'm stuck with is putting this into a loop so that it'll continue down the string, using each record length field as it goes, to strip out the data
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Splitting file into separate files based on record lengths and identifiers
by monty77 (Initiate) on Aug 27, 2010 at 17:49 UTC | |
|
Re^3: Splitting file into separate files based on record lengths and identifiers
by Marshall (Canon) on Aug 27, 2010 at 19:05 UTC |