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?