On 12/12/06, Dukelow, Don <[EMAIL PROTECTED]> wrote:
I'm trying to declare a zero size hash so a sub function can populate it and
be see by all other sub's.
my %loginHash();
my %loginHash;
should be enough.
But the "use strict" doesn't like it.
It is not "use strict" that does not like it. It is Perl itself --
this is a syntax error:
$ perl -e 'my %h();'
syntax error at -e line 1, near "%h("
Execution of -e aborted due to compilation errors.
All examples of making a hash
structure is hard coded in the program or is made reading from a file. When
I try to run the script all I get is syntax error near "%loginHash("
What am I missing?
Something like this might do what you want:
# read a file and store each line at a bucket of a hash
sub pop_hash {
my $h = shift; # the hash ref
my $f = shift; # the filehandle
while (<$f>) {
$h->{$.} = $_;
}
return $h; # but it was already changed in-place
}
my %h;
pop_hash(\%h, *STDOUT);
use Data::Dumper;
print Dumper(\%h);
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>