THIS IS NOT A SHELL SCRIPT! DON'T ENCLOSE VARIABLES IN DOUBLEQUOTES!
Sorry for screaming, but foo( "$varname") or $hash{"$varname"} is a sure sign you misunderstood something. And you are begging for problems. If the variable contains a number, then by enclosing it in double quotes you force perl to convert it to a string and make a copy of that string. If it's already a string you only make a copy. Just a waste, BUT if it's a reference you kill the reference. The thing you end up with will no longer be a reference. It will be just a string that will look a bit as if it was a reference but it will not work:
my %h = (a => 5, b => 9); my $ref = \%h; print "\$ref->{a}=$ref->{a}\n"; my $not_ref = "$ref"; print "\$not_ref->{a}=$not_ref->{a}\n"; print "Even though $ref == $not_ref\n";
While there are valid reasons to force stringification to a variable, they are very very rare! So please drop all your doublequotes around your variables!
Update: Anno is right, $ref == $not_ref evaluates to false, $ref eq $not_ref would evaluate to true. I meant
I should have written it like that.print "Even though $ref looks like $not_ref\n";
In reply to Re: Need a hand with rebuilding hashes out of a db.
by Jenda
in thread Need a hand with rebuilding hashes out of a db.
by swares
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |