R
Ray
Hi all,
I've been trying to figure out how to pass a hash (and a hash of
hashes) into a function. After some fiddling around and reading
perlreftut, I think I got it. However, I turned on "use strict" and
it is warning me that what I am doing is "deprecated" and may not be
supported in the future. So, even though it works (I mean...I get the
right answer), can someone tell me what the supported way?
I made a small example to demonstrate my problem:
-----
#!/usr/bin/perl -w
use strict;
use diagnostics;
my %cities;
my %states;
sub printStates {
my $href = shift @_;
## Next line is deprecated
printf (STDOUT "* %s\n", %{$href} -> {"New York"});
}
sub printCities {
my $href = shift @_;
## Next line is also deprecated
printf (STDOUT "* %s\n", %{$href} -> {"San Francisco"}{"LA"});
}
$cities{"San Francisco"}{"LA"} = "near";
$cities{"San Francisco"}{"New York"} = "far";
$states{"San Francisco"} = "California";
$states{"New York"} = "New York";
printf (STDOUT "%s\n", $cities{"San Francisco"}{"LA"});
printf (STDOUT "%s\n", $cities{"San Francisco"}{"New York"});
printf (STDOUT "%s\n", $states{"San Francisco"});
printf (STDOUT "%s\n", $states{"New York"});
printf (STDOUT "%s\n", \%states);
printStates (\%states);
printCities (\%cities);
-----
The warnings are:
Using a hash as a reference is deprecated at ./foo.pl line 11 (#1)
(D deprecated) You tried to use a hash as a reference, as in
%foo->{"bar"} or %$ref->{"hello"}. Versions of perl <= 5.6.1
used to allow this syntax, but shouldn't have. It is now
deprecated, and will
be removed in a future version.
Using a hash as a reference is deprecated at ./foo.pl line 17 (#1)
which are good in telling me what I did wrong, but I have no clue on
how to correct it. Any ideas?
Thanks in advance!
Ray
I've been trying to figure out how to pass a hash (and a hash of
hashes) into a function. After some fiddling around and reading
perlreftut, I think I got it. However, I turned on "use strict" and
it is warning me that what I am doing is "deprecated" and may not be
supported in the future. So, even though it works (I mean...I get the
right answer), can someone tell me what the supported way?
I made a small example to demonstrate my problem:
-----
#!/usr/bin/perl -w
use strict;
use diagnostics;
my %cities;
my %states;
sub printStates {
my $href = shift @_;
## Next line is deprecated
printf (STDOUT "* %s\n", %{$href} -> {"New York"});
}
sub printCities {
my $href = shift @_;
## Next line is also deprecated
printf (STDOUT "* %s\n", %{$href} -> {"San Francisco"}{"LA"});
}
$cities{"San Francisco"}{"LA"} = "near";
$cities{"San Francisco"}{"New York"} = "far";
$states{"San Francisco"} = "California";
$states{"New York"} = "New York";
printf (STDOUT "%s\n", $cities{"San Francisco"}{"LA"});
printf (STDOUT "%s\n", $cities{"San Francisco"}{"New York"});
printf (STDOUT "%s\n", $states{"San Francisco"});
printf (STDOUT "%s\n", $states{"New York"});
printf (STDOUT "%s\n", \%states);
printStates (\%states);
printCities (\%cities);
-----
The warnings are:
Using a hash as a reference is deprecated at ./foo.pl line 11 (#1)
(D deprecated) You tried to use a hash as a reference, as in
%foo->{"bar"} or %$ref->{"hello"}. Versions of perl <= 5.6.1
used to allow this syntax, but shouldn't have. It is now
deprecated, and will
be removed in a future version.
Using a hash as a reference is deprecated at ./foo.pl line 17 (#1)
which are good in telling me what I did wrong, but I have no clue on
how to correct it. Any ideas?
Thanks in advance!
Ray