http://www.perlmonks.org?node_id=222245


in reply to writing to arrays

Using the flip-flop operator:

#!/usr/bin/perl -w use strict; my @darray; my $set; my $eo; while ( <DATA> ) { chomp(); $eo = ( />DATA SET/ .. />DATA SET/ ); /DATA SET (\d+)/; if ( $1 ) { $set = $1; } if ( $eo =~ /E0/ ) { $darray[$set] .= $_."\n"; next; } $darray[$set] .= $_."\n" if ( $set ); } for ( my $c = 0 ; $c <= $#darray ; $c++ ) { print "array element: $c\n"; print "$darray[$c]\n"; } __DATA__ >DATA SET 1 HSAJDHSDHSADHDSALHDASLDHSALDH HGDKJSHDSADHSALDHLHLDHASDLSAH HKJAHCADHALIDHALSDHLSADHALHDA >DATA SET 2 HSAJDHSDHSADHDSALHDASLDHSALDH HGDKJSHDSADHSALDHLHLDHASDLSAH HKJAHCADHALIDHALSDHLSADHALHDA >DATA SET 3 HSAJDHSDHSADHDSALHDASLDHSALDH HGDKJSHDSADHSALDHLHLDHASDLSAH HKJAHCADHALIDHALSDHLSADHALHDA >DATA SET 4 HSAJDHSDHSADHDSALHDASLDHSALDH HGDKJSHDSADHSALDHLHLDHASDLSAH HKJAHCADHALIDHALSDHLSADHALHDA >DATA SET 5 HSAJDHSDHSADHDSALHDASLDHSALDH HGDKJSHDSADHSALDHLHLDHASDLSAH HKJAHCADHALIDHALSDHLSADHALHDA >DATA SET 6 HSAJDHSDHSADHDSALHDASLDHSALDH HGDKJSHDSADHSALDHLHLDHASDLSAH HKJAHCADHALIDHALSDHLSADHALHDA

_ _ _ _ _ _ _ _ _ _
- Jim
Insert clever comment here...