in reply to [untitled node, ID 178434]
in thread [untitled node, ID 178427]
foreach $element( keys %count ) { $name = $element; push @referrers, [ $element, $name, $count ]; } my @sorted_referrers = sort { $a->[2] cmp $b->[2] } @referrers; print "@$_\n" for @referrers; print "@$_\n" for @sorted_referrers;
I suggest you read up on references - perlreftut is a good place to start.
Lastly, it looks as though you're neither using strict nor enabling warnings. While they cause extra work by forcing you to use my all over the place, they will also save you from subtle bugs caused by typos, or variables that are visible or retain their value in parts of the code where you didn't intend them to. Save your own and your successor's sanity by getting into the habit of using strictures and warnings for anything longer than 5 lines at most.
Update: I realize these prints there must look somewhat confusing. I should probably give you a verbose, spelled out version:or a really ugly version which dereferences each separate element and prints them with pipes, solely for the purpose of the demonstration of the two syntaxes to access a referenced array's members:foreach my $referrer (@referrers) { print "$@referrer\n"; }
I prefer the arrow syntax. (Outside demonstration purposes, I'd solve this as follows:foreach my $referrer (@referrers) { print $referrer->[0] . "|" . $$referrer[1] . "|" . $referrer->[2] +. "\n"; }
foreach my $referrer (@referrers) { print join "|", $@referrer; }
which obviously isn't much of an example.
Again, perlreftut is the doc to read. Hope this helps. :)Makeshifts last the longest.
|
|---|