tobeythorn has asked for the wisdom of the Perl Monks concerning the following question:
I'm new to Perl and have hit a brick wall trying to make an array of references to hashes. My hosted server has Perl 5.8.8 installed. Here's the relavent part of my code, stripped down. I'm trying to find all files in a directory and for each call the filer function which should make a hash with some information about the file and push a reference to that hash unto an array
@files = (); sub filer { $filepath_rs = $File::Find::name; if(-f $filepath_rs) { $metadata = {}; #should instantiate a new hash object and retu +rn a scalar reference. ${metadata}{'path'} = $filepath_rs; print ${metadata}{'path'}; #prints out fine push(@files, $metadata); #should add reference to hash to arra +y. } } find(\&filer, $mydir); foreach(@files) { print ${$_}{'path'}; #nothing prints out }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array of Hashes
by roboticus (Chancellor) on Oct 28, 2011 at 15:47 UTC | |
|
Re: Array of Hashes
by aaron_baugher (Curate) on Oct 28, 2011 at 18:02 UTC | |
|
Re: Array of Hashes
by johnny_carlos (Scribe) on Oct 28, 2011 at 16:12 UTC | |
|
Re: Array of Hashes
by ~~David~~ (Hermit) on Oct 28, 2011 at 16:55 UTC | |
|
Re: Array of Hashes
by tobeythorn (Initiate) on Oct 28, 2011 at 19:02 UTC | |
by Anonymous Monk on Oct 28, 2011 at 19:30 UTC | |
by tobeythorn (Initiate) on Oct 28, 2011 at 20:03 UTC | |
|
Re: Array of Hashes
by Marshall (Canon) on Oct 29, 2011 at 11:49 UTC |