Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Variable assignment after logical OR

by johngg (Canon)
on Oct 02, 2007 at 19:08 UTC ( [id://642209]=note: print w/replies, xml ) Need Help??


in reply to Variable assignment after logical OR

snopal has pointed you towards using or instead of || because the former is a lower-precedence equivalent of the latter. Another way to solve your problem would be to use parentheses with your open so the || doesn't bind the file name and the flag together.

open(FILE, ">test.txt") || $failed_flag = 1;

It is often recommended these days to use the three-argument form of open with lexical filehandles, like this.

open my $testFH, '>', 'test.txt' or $failed_flag = 1;

Cheers,

JohnGG

Update: I really must learn to type faster :(

Replies are listed 'Best First'.
Re^2: Variable assignment after logical OR
by rq-2102 (Acolyte) on Oct 02, 2007 at 19:36 UTC
    Thanks all for the help and advice! For now I've switched from "||" to "or" but I'll definitely try to make a habit of using the new open statement as well, in this case it's not an option but it's good to know.
    --------- brian
      Why is it not an option?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-25 23:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found