I have a function which looks as follows:
convertToFile($dir,$name,@data);
I had a hash that has files as keys and timestamps as values. But now I have changed the hash a little.
The keys of the new hash are directories and the values are the previous hash (meaning keys = files values = time).
hash before:
$newHash{$file} = $time;
hash after:
$newHash{$dir}{$file} = $time;
I were passing the hash keys as array to the convertToFile function:
convertToFile($dir,$name,sort(keys(%data)));
But now it won't work because I need the nested hashes.
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:
%full = (%files1,%files2);
What if I have two keys (which are directories) that are the same? will it combine the inner hashes?
For example:
$files1 = {
'ABC' => {
'file1' => 6
'file2' => 5
'file3' => 8
}
'XYZ' => {
'file5' => 6
'file2' => 5
'file8' => 8
}
};
$files2 = {
'ABC' => {
'file1' => 9
'file8' => 5
'file3' => 8
}
};
How the new hash will look like?
Thank you
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.