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

Re: Hashes of hashes

by inman (Curate)
on Jan 15, 2007 at 14:27 UTC ( [id://594746]=note: print w/replies, xml ) Need Help??


in reply to Hashes of hashes

Example solution with comments
#! /usr/bin/perl -w use strict; use Data::Dumper; my %hash; while (<DATA>){ # remove the newline chomp; # Split the data into an array my @data = split /,/,$_; # Match the filename and extension if ($data[2] =~ /(\w+)\.(\w+)/){ # push push @{ # onto an array refered to by the hash value $hash{lc $2}{$1} }, # array values using a slice @data[3,4]; } } print Dumper(\%hash); __DATA__ abc,def,excel1.xls,12,some,time hj,uyi,excel2.xls,12,more,time2 gh,ty,word1.doc,234,thing,time2 ksdj,hsjh,word2.doc,334,is,time3
yields
$VAR1 = { 'doc' => { 'word2' => [ '334', 'is' ], 'word1' => [ '234', 'thing' ] }, 'xls' => { 'excel2' => [ '12', 'more' ], 'excel1' => [ '12', 'some' ] } };

Replies are listed 'Best First'.
Re^2: Hashes of hashes
by Anonymous Monk on Jan 16, 2007 at 04:24 UTC
  • neat !!
  • Thanks

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (9)
As of 2024-04-19 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found