Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: writing to arrays

by Wonko the sane (Deacon)
on Dec 26, 2002 at 13:56 UTC ( [id://222345]=note: print w/replies, xml ) Need Help??


in reply to writing to arrays

Another way to do this, keeping the index of array as the number of the DATA SET

#!/usr/local/bin/perl -w use strict; use Data::Dumper; my @records; { local $/ = '>'; # record separator. while ( <DATA> ) { push( @{$records[$1]}, split(/(?:\n+|>)/) ) if ( s/DATA SET ([0-9]+)\n+// ); } } print Dumper( \@records ); __DATA__ >DATA SET 1 1aHSAJDHSDHSADHDSALHDASLDHSALDH 1bHGDKJSHDSADHSALDHLHLDHASDLSAH 1cHKJAHCADHALIDHALSDHLSADHALHDA >DATA SET 2 2aHSAJDHSDHSADHDSALHDASLDHSALDH 2bHGDKJSHDSADHSALDHLHLDHASDLSAH 2cHKJAHCADHALIDHALSDHLSADHALHDA >DATA SET 3 3aHSAJDHSDHSADHDSALHDASLDHSALDH 3bHGDKJSHDSADHSALDHLHLDHASDLSAH 3cHKJAHCADHALIDHALSDHLSADHALHDA

Some extra juggling is done to clean output. This is what it looks like.

:!./test.pl $VAR1 = [ undef, [ '1aHSAJDHSDHSADHDSALHDASLDHSALDH', '1bHGDKJSHDSADHSALDHLHLDHASDLSAH', '1cHKJAHCADHALIDHALSDHLSADHALHDA' ], [ '2aHSAJDHSDHSADHDSALHDASLDHSALDH', '2bHGDKJSHDSADHSALDHLHLDHASDLSAH', '2cHKJAHCADHALIDHALSDHLSADHALHDA' ], [ '3aHSAJDHSDHSADHDSALHDASLDHSALDH', '3bHGDKJSHDSADHSALDHLHLDHASDLSAH', '3cHKJAHCADHALIDHALSDHLSADHALHDA' ] ];

Best Regards,
Wonko

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-19 01:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found