Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: how to split the elements in an array of arrays ?

by ptum (Priest)
on Oct 31, 2006 at 18:54 UTC ( [id://581544]=note: print w/replies, xml ) Need Help??


in reply to Re^2: how to split the elements in an array of arrays ?
in thread how to split the elements in an array of arrays ?

Perhaps I am not understanding you correctly, but this seems to be a very different question than the one you asked first. In the example you gave, what happens to the values in $entry, $title, $org or $acc? You seem to drop them on the floor ...

To solve this kind of a problem, I would probably establish a hash of array references, something like this (untested):

use strict; my %filecontents = ('entries' => [], 'titles' => [], 'organisms' => [], 'accessions' => [], 'unknown' => [] ); my $filehandle; unless (open($filehandle,"<file.txt")) { die "Cannot open file.txt: $!"; } while (<$filehandle>) { chomp; if (/^ENTRY/) { push @{$filecontents{'entries'}}, $_; } elsif (/^TITLE/) { push @{$filecontents{'titles'}}, $_; } # and so on ... }

Update: Notice, by the way, that I check for success in opening the filehandle, always a good thing to do.

Update 2: Arrghh! I was duped! I didn't realize you'd asked this question before. Why not pay attention to the answers you've already received, as Fletch points out below?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-03-29 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found