Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: using warn instead or print STDERR?

by TGI (Vicar)
on Feb 27, 2009 at 00:20 UTC ( #746713=note: print w/ replies, xml ) Need Help??


in reply to using warn instead or print STDERR?

Thanks for asking such an interesting question. I learned from the responses.

This is barely not offtopic, or something. I'd like to make a suggestion and ask a question.

IMO, these kind of debugging output lines are a perfect place to use the dreaded postfix if. I find:

warn "Watch out, there a llamas!\n" if $DEBUG;
to be clearer than:
$DEBUG and warn "Watch out, there a llamas!\n";

I guess its becuase the short circuit in the 'and' is not part of the meaning of the English word. The use or for things like open(...) or die "Ugh." doesn't bother me, because the sense is the same in English as in Perl.

Is there a particular reason you like to use the $DEBUG and ... form?


TGI says moo


Comment on Re: using warn instead or print STDERR?
Select or Download Code
Re^2: using warn instead or print STDERR?
by rhesa (Vicar) on Feb 27, 2009 at 00:27 UTC
    "Three strikes and you're out"
Re^2: using warn instead or print STDERR?
by leocharre (Priest) on Feb 27, 2009 at 21:01 UTC
    Well.. Here's what I've done out of this discussion thread.
    It's a little bit mischievious.. but.. it's ok for now..

    Let's imagine script.pl

    #!/usr/bin/perl use strict; use Getopt::Std::Strict 'dh'; INIT { $SIG{__WARN__} = $opt_d ? sub { warn(" # @_\n") } : sub { 1 }; $opt_h and print usage() and exit; } warn "Hi there. I am stuff, very interersting stuff."; sub usage { "-d flag to see interesting stuff\n" }

    So essentially, I can code debug into an existing class or script, that simply turns warnings off or on via something like an option flag or a class DEBUG variable. Very sexy.

    Back to your point.

    Yes, I have to hand it to you .. "$DEBUG and ..." is not as clear as "... if $DEBUG". To the normal human being. I think I've been using and or ? : so much that you just start to think like the interpreter a little bit so.. it becomes part of your language at the time. I feel no difference between "x and y" and "y if x". Odd.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (15)
As of 2014-10-23 14:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls