http://www.perlmonks.org?node_id=969726


in reply to unless vs. bare block

choroba's answer should get you past your messages; this comment addresses your approach:

unless (open (QTREES, $file)) { print STDERR "WARNING: get_qtrees() can't open $file for filer $fi +ler!\n";

is unnecessarily verbose. In the first example, you could achieve the same end with:

unless (open (QTREES, $file) or warn "get_qtrees() can't open $file for filer $filer!\n");

Similarly, in the second,

open (QTREES, $file) or warn "get_qtrees() can't open $file for filer $filer!\n";

Replies are listed 'Best First'.
Re^2: unless vs. bare block
by BrowserUk (Patriarch) on May 10, 2012 at 02:41 UTC
    unnecessarily verbose. In the first example, you could achieve the same end with:

    That's a syntax error:

    $x=1; unless( $x ) or warn 'Erk!';; [syntax error at (eval 11) line 1, near ") or"

    Remember that unless is a 'negative' if, and Perl doesn't support if without a block.

    Ie. In perl, if( cond ) statement must be coded as if( cond ) { statement; }


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

       warn "can't open ... " unless open ...;
        If is necessary to wear a crash helmet when riding a motorbike.
        You don't have to wear a crash helmet when riding a pushbike.

        Both true statements; the presence of 'bike' in both does not make them contradictory.

        Ditto: unless( cond ) { statement; } and statement unless cond;.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?