in reply to Re: Hashes of hashes
in thread Hashes of hashes

  • Looking for :
  • <li> RESULT</li> $VAR1 = { 'xls' => [ 'excel1', { 'excel1'=>['12','some'] } 'excel2', { 'excel2'=>[12,more] } ] };

    I have a lot of file typeslike xls,doc.... I want "file_type" to be the firt key which contains all the files of that types and each of these files second keys which in turn have an array as its value.

  • Thanks
  • Replies are listed 'Best First'.
    Re^3: Hashes of hashes
    by wfsp (Abbot) on Jan 15, 2007 at 11:01 UTC
      You were nearly there!
      #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hoh; while(<DATA>){ my $line=$_; chomp($line); my @values=split(/,/,$line); my @type_val=splice(@values,3,2); my ($type_value,$key_type)=split(/\./,$values[2]); $hoh{$key_type}{$type_value} = [@type_val]; } print Dumper \%hoh; __DATA__ abc,def,excel1.xls,12,some,time hj,uyi,excel2.xls,12,more,time2
      output:
      ---------- Capture Output ---------- > "c:\perl\bin\perl.exe" _new.pl $VAR1 = { 'xls' => { 'excel2' => [ '12', 'more' ], 'excel1' => [ '12', 'some' ] } }; > Terminated with exit code 0.
      • COOL !! Thanks so much
      • yea..Works