Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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
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 meditating upon the Monastery: (13)
As of 2014-08-21 13:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (135 votes), past polls