ovedpo15 has asked for the wisdom of the Perl Monks concerning the following question:
I have a function which looks as follows:
The keys of the new hash are directories and the values are the previous hash (meaning keys = files values = time).
hash before:
I don't care about the order of the hashes I just care about the files.
I want to pass file to a the function and it does not matter from which directory.
I was wondering if its possible to do without any additional loops or code, maybe some special keywords.
Another related small question:
I were using the following syntax to combine two hashes into one:
For example:
Thank you
I had a hash that has files as keys and timestamps as values. But now I have changed the hash a little.convertToFile($dir,$name,@data);
The keys of the new hash are directories and the values are the previous hash (meaning keys = files values = time).
hash before:
hash after:$newHash{$file} = $time;
I were passing the hash keys as array to the convertToFile function:$newHash{$dir}{$file} = $time;
But now it won't work because I need the nested hashes.convertToFile($dir,$name,sort(keys(%data)));
I don't care about the order of the hashes I just care about the files.
I want to pass file to a the function and it does not matter from which directory.
I was wondering if its possible to do without any additional loops or code, maybe some special keywords.
Another related small question:
I were using the following syntax to combine two hashes into one:
What if I have two keys (which are directories) that are the same? will it combine the inner hashes?%full = (%files1,%files2);
For example:
How the new hash will look like?$files1 = { 'ABC' => { 'file1' => 6 'file2' => 5 'file3' => 8 } 'XYZ' => { 'file5' => 6 'file2' => 5 'file8' => 8 } }; $files2 = { 'ABC' => { 'file1' => 9 'file8' => 5 'file3' => 8 } };
Thank you
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: how to get all keys of inner hashes
by 1nickt (Canon) on Jan 10, 2019 at 14:41 UTC | |
Re: how to get all keys of inner hashes
by Laurent_R (Canon) on Jan 10, 2019 at 15:02 UTC | |
Re: how to get all keys of inner hashes
by hippo (Bishop) on Jan 10, 2019 at 15:27 UTC | |
Re: how to get all keys of inner hashes
by choroba (Cardinal) on Jan 10, 2019 at 15:54 UTC | |
by ovedpo15 (Pilgrim) on Jan 10, 2019 at 15:56 UTC | |
by poj (Abbot) on Jan 10, 2019 at 17:02 UTC |
Back to
Seekers of Perl Wisdom