I have a table that produces the following results:
DIR FILE_NAME
| 954 | 24088954 |
| 955 | 24052955 |
| 955 | 24111955 |
| 955 | 24130955 |
| 956 | 23159956 |
| 957 | 24133957 |
| 958 | 24131958 |
| 960 | 24093960 |
| 961 | 24033961 |
| 961 | 24129961 |
| 961 | 24130961 |
I am trying to create a hash of these values based on the directory:
955 -> 24052955, 24111955, 24130955
961 -> 24033961, 24122961, 24130961
I am guessing that I need to hash the directory, but then have an array as the value of the hash
The problem I have is that when I did
$file_hash->{$dir}{push(@file_array,$file_name)};
I get duplicates
foreach my $file_dir (sort (keys % {$file_hash}))
{
foreach my $file (@file_array){
print "$counter Directory: $file_dir $file\n";
$counter++;
+ }
+ }
1 Directory: 000 24090000
2 Directory: 000 24125002
3 Directory: 000 24011003
4 Directory: 000 24070003
5 Directory: 000 24082003
6 Directory: 000 24065005
7 Directory: 000 24070007
8 Directory: 000 24132007
9 Directory: 000 24041008
As you can see, the second record here doesn't belong (the last three digits of the file name correspond to the directory).
So it would seem that I need to pre-define 1000 different arrays, one for each directory, and then do an if statement to push the values into the approriate array,but I am sure there is a better way to handle this.
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.