Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: calling sub and returning value from the same line

by jdalbec (Deacon)
on Jan 09, 2005 at 20:43 UTC ( #420744=note: print w/replies, xml ) Need Help??


in reply to calling sub and returning value from the same line

Is error() returning a false value? That would cause the behavior you describe. Remember that <EXPR> and <EXPR> executes the second expression only if the first expression is true. To avoid this dependence on the return value of error() you could try
unless (open FH, ">$_[0]") { error($!, "not able to write to file $_[0]"); return undef; }

Replies are listed 'Best First'.
Re^2: calling sub and returning value from the same line
by dpuu (Chaplain) on Jan 09, 2005 at 21:00 UTC
    Another alternative is to replace the "and" operator with a comma:
    open FH, ">$file" or error("msg"), return undef;
    If you do this, you must use parentheses to call the "error" function.

    --Dave
    Opinions my own; statements of fact may be in error.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2023-12-10 04:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (38 votes). Check out past polls.

    Notices?