Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: writing to arrays

by snafu (Chaplain)
on Dec 25, 2002 at 21:20 UTC ( #222245=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://222245]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2019-07-22 22:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?






    Results (22 votes). Check out past polls.

    Notices?