Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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: (4)
As of 2020-08-07 21:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (50 votes). Check out past polls.

    Notices?