in reply to Code Blocks

Looks like you are bending over backwards to write obscure code. In fact it is so obscure that it's not even clear what you are trying to achieve. What is the desired result if the file exists?

I suspect your code would be easier to understand and maintain if you use a simple if rather than try to be clever with logic operators.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Code Blocks
by Ronnie (Scribe) on Jul 27, 2006 at 13:11 UTC
    Sorry but I assumed from the sub name - toytown - that you'd work out that it's not production code just a small example of what I was trying to do. Thanks for the help, I've found 2 working options from the responses that I've had. Cheers, Ronnie

      Posting a short clear represntative sample is to be appluded (or up voted anyway). Posting something untidy and obscure that can not be easily run and doesn't seem to illustrate the issue at hand will not get you the best posible help (the down votes are incedental in that case).

      Although it's not clear from your original post, it may be that you were trying to execute several statements when something failed. There are ways to do that as others have mentioned (perhaps omitting the comma operator - see below). But much better is to use an if/else.

      Using an if makes it clear that a test is being made and what gets executed as a result of the test. It is easy to add stuff to be executed for the fail or success case without a lot of mental exercise. The code is easier to understand and easier to maintain.

      Oh, and the comma operator? I don't recommend it but:

      use warnings; use strict ; 0 or (print 'this'), (print " and that\n");

      DWIM is Perl's answer to Gödel