3/18 In Perl, I'm using a hash of a hash like the following:
my $w=$CATEGORY{$c};
my %w=%$w;
But after turning on strict, it no longer works and reports
Can't use an undefined value as a HASH reference at bin/categorize.pl line 72.
What am I doing wrong? Thanks.
\_ What does $CATEGORY{$c} return? A hash? you probably want a
reference to it, not a copy. And that would help you sort out
the access on the next line.
\_ You probably mean "%w = %{$w}", but why not just use the pointer?
-scotsman
\_ I'd like to use %w like $w{$key}=$val. So can I actually
reference/deference in Perl? Problem with Perl is I don't
know when I'm copying by value or copying by reference...
\_ Well, the first line there is copying by reference. My
correction of the second line copies by value. The %{}
is a dereference as well as a "cast". -scotsman
\_ same problem even with cast, whats wrong?
\_ ok I just found out that when I set to use strict,
%CATEGORY becomes empty even though I made it
public by "use vars qw (%CATEGORY)". So now
I'm just scratching my head...
NEVERMIND I found it's a logic problem and _/
has NOTHING to do with use strict. I really
like "use strict"! I've caught a lot of bugs
with it. |