http://www.perlmonks.org?node_id=594746


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