Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: reading file in Hash

by perliff (Monk)
on May 07, 2009 at 14:44 UTC ( [id://762620]=note: print w/replies, xml ) Need Help??


in reply to reading file in Hash

You can also try to use the Data::CTable module. Here's a one way you can do to get the final data structure you need. You should read more module documentation for the Data::CTable module if you need more functions to access/modify the data.
#!/usr/bin/perl use strict; use Data::Dumper; use Data::CTable; my $table = Data::CTable->new("data.txt"); $table->clean_ws(); # a bit of a clean up my $fields = $table->fieldlist_all(); my %final_hash; foreach my $col ( @$fields ) { $final_hash{$col} = $table->{$col} ; ## Get a column you know + exists } print Dumper \%final_hash;
gives the output...
$VAR1 = { '1' => [ 'a', 'b', 'c' ], '3' => [ 'x', 'y', 'z' ], '2' => [ 'p', 'q', 'r' ] };

perliff

----------------------

"with perl on my side"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-04-18 12:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found