I encountered some strange behavior which hints that I do not understand some basic things about Perl script execution and initialization order. The following example:
#!/usr/bin/env perl
use strict;
use warnings;
print &get_keys(), "\n";
use vars qw/%hello/; # same effect with 'my %hello = (...);'
%hello = ( a => 1, b => 2 );
sub get_keys
{
return join(', ', sort keys %hello);
}
prints an empty string. Meaning that though variable is already visible, since the state with assignment wasn't yet reached, it has no value. (Using a scalar instead of the hash would trigger a warning about uninitialized variable.)
Is that intended behavior?
I would be also glad for the RTFM pointers.