Mailing List Archive

empty hashes in 5.001n
I was finally going to update to 5.001m and discovered that 5.001n is
out. I installed it and my makedepend script broke. here is the
sort of thing I get:


ahab% more hash_bug
#!/usr/bin/perl
# hash containing names of included files
%inc_files = {};

$inc_files{'star.F'} = 'hash.h';
$inc_files{'tar.cc'} = 'hash.h';

foreach $file (keys %inc_files) {
$ref = $inc_files{$file};
print " $file: $ref\n";
}
ahab% hash_bug
Odd number of elements in hash list at hash_bug line 3.
HASH(0x8f438):
tar.cc: hash.h
star.F: hash.h
ahab% perl -v

This is perl, version 5.001

Unofficial patchlevel 1n.

Copyright 1987-1994, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.


Kate
Re: empty hashes in 5.001n [ In reply to ]
On Mon, 6 Nov 1995, Kate Hedstrom wrote:

> ahab% more hash_bug
> #!/usr/bin/perl
> # hash containing names of included files
> %inc_files = {};

That's 'cos {} gives you a reference to a hash which is a single value, so
you're either going to have to say

$hashRef = {};

...

$hashRef->{'key'} = 'value';

or

%hash = ();
...
$hash{'key'} = 'value';

Hope this helps,

Mike

--
Mike Stok | The "`Stok' disclaimers" apply.
stok@pencom.com | Pencom Systems Administration (work)
stok@cybercom.net | Cyber Access (play)
http://www.cybercom.net/~stok/ | The inevitable WWW page (?)
Re: empty hashes in 5.001n [ In reply to ]
> That's 'cos {} gives you a reference to a hash which is a single value, so
> you're either going to have to say
>
> $hashRef = {};
>
> ...
>
> $hashRef->{'key'} = 'value';
>
> or
>
> %hash = ();
> ...
> $hash{'key'} = 'value';
>
> Hope this helps,

Thanks! It did what I wanted back in 5.001l...

Kate