Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Hashes of hashes

by inman (Curate)
on Jan 15, 2007 at 14:27 UTC ( #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' ] } };


Comment on Re: Hashes of hashes
Select or Download Code
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
Node Status?
node history
Node Type: note [id://594746]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2015-07-29 11:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls