|
|
| Pathologically Eclectic Rubbish Lister | |
| PerlMonks |
Re^11: Comparing Values PER Sub-folderby Kenosis (Deacon) |
| on Sep 05, 2012 at 21:34 UTC ( #991951=note: print w/ replies, xml ) | Need Help?? |
|
The following pieces together the script segments:
Notice that we now have my %dirLines; at the top. We'll use this hash for a hash of arrays (HoA), where the key will be the directory path and the associated value is an array whose elements are file numLines. The following was added to the countLines subroutine:
$dirLines{$curDir} is our hash and the value of $curDir is used as a key. The enclosing @{ } notation says to treate this as an array (we'll see this later, too), and then we push the value of $numLines onto that array. Data::Dumper was used to help visualize our hash's data structure after traversing the directories:
Curley braces {} mean a hash; square brackets [] mean an array. From the output above, you can see the association between a key (directory path) and an array (a list of file line numbers) as a value. The next step is to process our hash, iterating through its keys--one at a time--and that starts as follows:
Each sorted key of %dirLines is assigned to $dir. Next is the same notation seen earlier, viz., @{ $dirLines{$dir} }. The directory's associated array of numLines is sent to sameArrayElements to check for element sameness. The following line prints the result of this check:
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||