On Fri, 2009-01-23 at 11:57 -0800, jeffqt...@gmail.com wrote:
> 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
> 
> Jeff
> 
> 
You can capture a match in an array but not a substitute.

my @capture = $_ =~ /^(.{3})(.{24})(.{6}).../

You can also use unpack to achieve the same thing:

#!/usr/bin/perl

use strict;
use warnings;

while( <> ){
  chomp;
  my @data = unpack( 'a3a26a6', $_ );
  print "@data\n";
}

See `perldoc -f unpack` and `perldoc -f pack` for details.


-- 
Just my 0.00000002 million dollars worth,
  Shawn

"It would appear that we have reached the limits of what it is
 possible to achieve with computer technology, although one should
 be careful with such statements, as they tend to sound pretty silly
 in 5 years."
   --John von Neumann, circa 1960


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to