View Single Post
  #7   (View Single Post)  
Old 6th February 2014
thirdm thirdm is offline
Spam Deminer
 
Join Date: May 2009
Posts: 234
Default

Quote:
Originally Posted by ocicat View Post
My suggestion would be to post to http://perlmonks.org/.
This post is kind of apropos to what I'm getting at: http://www.perlmonks.org/?node_id=680611

A difference between the code you've posted and the pkg-config case is that in your case you only need care if it's undefined before using the hash element. Had you wanted only to print "true" values and written ...

print "'$k'\t'$h{$k}'\n" if defined $h{$k} and $h{$k};

(or how about print "'$k'\t'$h{$k}'\n" if exists $h{$k} and defined $h{$k} and $h{$k}; )

... then I would be wondering why you hadn't simply written

print "'$k'\t'$h{$k}'\n" if $h{$k}

I can understand sprinkling extra defined checks around reflexively from getting yelled at by the Perl warnings. Maybe that's all it's about, plus C programmer instinct to guard against access to an undefined element, analogous to if (p && *p != '\0') ... . In which case, criticizing that practice might be annoying.

I'll look more closely at your script tonight, J65nko. My manager just got after me to make progress on what I'm supposed to be working on.
Reply With Quote