If you have complex arrays you might want to use the Data Dumper: [
perldoc.perl.org...]
I tend to wrap the Perl Data Dumper output in <pre> so it formats nicely in a web page as so:
use Data::Dumper;
print '<pre>'.Dumper(@sfiles).'</pre>';
Additionally, to add one more sort method to those above:
On the WebmasterWorld Top 100 Poster page, I have an array with all posters and their total number of posts.
It's a hash array with items like this:
$maxposts{'incredibill'} = '15000';
$maxposts{'engine'} = '30000';
$maxposts{'brett_tabke'} = '45000';
So here I've got something I need sorted by the values, not the keys which is how it typically works.
To accomplish this, use the following which sorts from largest to smallest value:
foreach $user (sort { $maxposts{$b} <=> $maxposts{$a} } keys %maxposts) {
print "USER: $user POSTS: $maxposts{$user}<br>";
}
If you want them in reverse order, low to high, simply swap $a and $b as follows:
foreach $user (sort { $maxposts{$a} <=> $maxposts{$b} } keys %maxposts) {
print "USER: $user POSTS: $maxposts{$user}<br>";
}