in reply to Array of Hashes
This does the same thing:#!/usr/bin/perl -w use strict; use File::Find; use Data::Dumper; my @files = (); #will be an Array of Hashes my $odd =1; sub filer { my $filepath_rs = $File::Find::name; return unless -f $filepath_rs; push(@files, {file=>$filepath_rs, OddEven => $odd}); $odd ^= 1; } find(\&filer, 'C:/temp'); print Dumper \@files;
Every time the subroutine filer is entered a new hash %metadata is created. If a reference to some previously created %metadata hash exists, then new memory is allocated for this instance of %metadata. If %metadata is a multi-dimensional hash, the same rules apply and a complete new hash and memory allocation will be made.#!/usr/bin/perl -w use strict; use File::Find; use Data::Dumper; my @files = (); #will be an Array of Hashes my $odd =1; sub filer { my $filepath_rs = $File::Find::name; return unless -f $filepath_rs; my %metadata; $metadata{file} = $filepath_rs; $metadata{OddEven} = $odd; push(@files, \%metadata); $odd ^= 1; } find(\&filer, 'C:/temp'); print Dumper \@files;
|
|---|