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

print "Even though $ref looks like $not_ref\n";
I should have written it like that.


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.