: I declare my hash like this:
:
: my ( %FS_XCPTN ); # hash table, key is mount point,
: # value is FS's special case H_LIMIT and
: C_LIMIT
:
: I use it like this:
: $FS_XCPTN{$mntPoint} = {
: H_LIMIT => "$l_limit",
: C_LIMIT => "$h_limit" };
:
: And keys returns the list correctly. But when I use it like this:
:
: $FS_XCPTN->{$mntPoint} = {
: H_LIMIT => "$l_limit",
: C_LIMIT => "$h_limit" };
:
: And run the keys on it, it doesn't seem to work. What am I doing wrong ?
The second notation is for a hash reference, not a hash. These are two
different things: The hash is an actual data structure, while a hash
reference is just a name that could point to a data structure (or it
could just be a regular scalar).
To make the hash reference work, you'd need to do it
like this:
my $FS_XCPTN = {}; # hash ref
...
$FS_XCPTN->{$mntPoint} = {
H_LIMIT => "$l_limit",
C_LIMIT => "$h_limit" };
...
foreach my $key ( keys %$FS_XCPTN ) {
...
}
"use strict" would probably have caught this (unless you actually
do have a scalar called $FS_XCPTN in addition to the hash %FS_XCPTN
in your script.
% perldoc perlref
-- tdk