This code was obviously written without strict and should therefore only serve as an example as to why strict should always be used. Anyways, on to the analysis:
The code is obviously supposed to sort its output by number of logins, but if you run it several times, you'll see it doesn't work!
First clue as to the error: If you turn on warnings and strict - as one always should, even when trying to understand legacy code! - and then declare our ($hash, %hash); at the top of the code, you'll see warnings like this: "Use of uninitialized value in numeric comparison (<=>) at ..."
sub KeysByLogins is the only place where %hash is referenced, and there it is only read from, not written to, that's why it remains empty.
If you break the Schwartzian Transform happening in that sub into pieces, you can see that happening:
sub KeysByLogins { my $hash = shift; my @temp = map { [ $hash{$_}->{logins}, $_ ] } keys %$hash; print Dumper(\@temp); return map { $_->[1] } sort { $a->[0] <=> $b->[0] } @temp; }
The first element in each pair is always undef, because %hash is empty.
So it's really not got much to do with the symbol table, just a single typo bug caused by not using strict.
In reply to Re: Question about the symbol table
by Anonymous Monk
in thread Question about the symbol table
by Cristoforo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |