Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: "Safe" print?

by ambrus (Abbot)
on May 14, 2013 at 08:23 UTC ( #1033434=note: print w/ replies, xml ) Need Help??


in reply to "Safe" print?

If you want undefined values printed as "undef", try

use 5.010; print $somevalue // "undef";


Comment on Re: "Safe" print?
Download Code
Re^2: "Safe" print?
by sundialsvc4 (Abbot) on May 14, 2013 at 13:45 UTC

    ... noting that the "//" operator is, IIRC, a relatively recent addition to the language.   You should have it, but you (or some backwater web-hosting companies who need not be named ...) conceivably might not.   See perldoc perlop on your system; look for the heading “C-style Logical Defined-Or.”

      See that first line in my the code? It says use 5.010;. The // operator was new in perl 5.10. It's not new anymore now.

        And that's right where I am (CENTOS 6 packaged Perl).

        I know and heartily approve the "//" operator (except when I somehow get confused and use backslashes), but don't want to have to write special code each time I print something that I can't prove is defined quickly. However, the Dumper suggestion (and related) is useful, I'm just embarrassed I didn't think of it myself (that's for complex structures! In debugging!).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1033434]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (15)
As of 2015-07-06 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (74 votes), past polls