[Chicago-talk] specifying 2 variables as 1 hash key

Jim Thomason jthomasoniii at yahoo.com
Wed Dec 3 13:47:13 CST 2003


I'd say to consider using a nested hash instead, if
possible.

$hash{$var1}->{$var2}

I think it's a bit cleaner.

But that's not always necessarily an option.

Regardless, it has to do with the parsing precedence.
Easiest way to fix it is to take it out of double
quotes.

print $hash{$var1 . $var2};

And, i just discovered, oddly enough you don't even
need to do that.

print "$hash{$var1 . $var2}";

also works. In fact, you seem to be able to stick any
executable code inside the hash key inside double
quotes. For example,

sub foo () {
  return join('', @_);
};

print "$hash{foo($var1, $var2)}";

Neat. I just learned a new trick. :)

-Jim....

--- "Dooley, Michael" <Dooley.Michael at con-way.com>
wrote:
> my $var3="$var1$var2"; 
> print "$hash{$var3}"; #this works.
> 
> -------------------
> 
> print "$hash{$var1$var2}"; #this does not work.
> 
> I kind of need to use 2 variable in the has and
> would rather not create a
> 3rd variable to use as the hash Key. am I just not
> labeling the key
> properly?
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at mail.pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk


__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/



More information about the Chicago-talk mailing list