> I am trying to split a very long fixed lenght record into its > constituents, and then load them into an array. I have patterns like > '^ > (.{3})(.{24})(.{6})...' which gets teh fields into $1, $2, $3 etc. I > am stumped however as to how to get them into an array in a general > way. With 'use strict' turned off I can force it with the ugly ${$i} > construct in a loop, but I would prefer something that was 'strict' > compatible. I havebasic. read the perodlc on @-, %-, %+, and none seem > to do what I want - but that probably because I am missing something > > So, any help gratefully accepted
Perhaps if you gave an example of your fixed length record we could help a bit better So lets say your fixed length record is 80 characters in length And let say you want it broken into 3, 24, 6, 7, 40 size elements. Then use unpack ( see perldoc -f unpack ) You would do something like this ============================================================ my $record = $_; # however you get the record my ( $bit1, $bit2, $bit3, $bit4, $bit5 ) = unpack "A3 A24 A6 A7 A40", $record; ============================================================ If you wish to get it out by regular expression, then my @array = ($1,$2, ... $5); print "$array[0],$array[1], ... $array[4]\n"; Owen -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/