> -----Original Message-----
> From: jeffqt...@gmail.com [mailto:jeffqt...@gmail.com] 
> Sent: Friday, January 23, 2009 12:58
> To: beginners@perl.org
> Subject: Loading results of pattern match into an array - help please
> 
> 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

        it does a double regex and one of the gurus can probably do it
without the double, but this does work:
#!/usr/bin/perl

use strict;
use warnings;

my @MyWorka = ();
while ( <DATA> ) {
    chomp;
    next if ( /^\s*$/ );
    if ( /(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ ) {
        @MyWorka = (/(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/);
        printf "<%s>\n",
                                join(q[|], @MyWorka );
     }
     else {
         printf " not correct number of fields on line to load into
array:\n";
         printf "(%6d)<%s>\n",
                                $.,
                                $_;
     }
 }
__DATA__

1234 1234 1235 1236 1237
1234 1234 1235 1236

Output:
<1234|1234|1235|1236|1237>
 not correct number of fields on line to load into array:
(     3)<1234 1234 1235 1236>
> 
> So, any help gratefully accepted
> 
> Jeff
> 
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
> 
> 
> 

--
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