Sorry, I wrote a bad example, my mistake. Please look at the complete code, I am trying to build hash of hashes where each folder is a key. Early I did hash of hashes where keys are full path to folder, but it wasn't pretty.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %filesystem; my $ref = $filesystem{root} ||= {}; traverse(".",""); sub traverse{ my ($folder,@path) = @_; opendir DIR,$folder; my @list = grep {!/^\.{1,2}$/} readdir DIR; # exclude . and .. closedir DIR; foreach my $entry(@list){ next if ( -l $folder."/". $entry); # skip links $ref = $$ref{$_} ||= {} for @path; if( -d $folder."/". $entry){ traverse($folder."/".$entry,@path,$entry); }else{ $$ref{$folder} = $entry; }; }; }; print Dumper(\%filesystem);
if I run it it eat all my RAM, so I think I use $ref from your example wrong
In reply to Re^2: Case of autovivification
by resistance
in thread Case of autovivification
by resistance
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |