Update: The first line is why this node is garnishing negative XP. Its wrong for a few reasons..both reasons are within the unless...
First off unless will only evaluate to true if the EXPR inside returns something other than '0', an empty sting '', or undef
Second is the NULL. In this context I was attempting to use it as a alias for '0' which is what perl does, but that was wrong because if we do 'unless( values(%hash) );' that works as well. If we had applied 'use strict;' to this code it would have broke as NULL is a bareword in this situation.
Justifications:
First: I've been coding a bunch of C lately as should be readily apparent to whomever knows C in the bunch. I just didn't fully context switch to perl when whipping out this code.
Second: There was a thread ( I will attempt to find and link to) which raised an interesting situation where when calling values on a newly created hash ( cant remember if it was actually a ref to a hash or not), the values would be autovivified. In that situation I ended up suggesting doing 'unless( join('', values %hash) );' which was the only way to consistantly check to see if the hash really had anything in it.
Sorry for the bad code, but I guess we can stop downvoting this node, and simply use it as an example for .... something somewhere I'm sure..
# will print "no keys" if all values are undef..
print "no keys\n" unless( values(%hash) != NULL );
# to resest a hash..
%hash = ();
# or if you are paranoid
undef(%hash) && %hash = ();
Happy hacking
MMMMM... Chocolaty Perl Goodness.....
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.