in reply to Confused by a couple of idioms

$csv and $xls = $csv;

Here and is used for control flow. It separates statements (or expressions) which are conditionally evaluated from left to right. The first is simply $csv and so the subsequent statement is only evaluated (and therefore executed) if this first expression is true. You can see then that the whole line is equivalent to writing

$xls = $csv if $csv;

Replies are listed 'Best First'.
Re^2: Confused by a couple of idioms
by rsFalse (Chaplain) on Feb 22, 2019 at 09:31 UTC
    Here this construction is equivalent, but variation with 'and' ends up as an expression and can be used further. E.g.,  print( $xls = $csv if $csv ); cause a syntax error, but with 'and' - don't.

    Also it is worth to mention that an alternative for "if( xxx ){ yyy }" one can use "xxx and do { yyy };" (with semicolon if it is the end of sentence; 'do BLOCK' in do docs)

      slight problem I see here (for me at least) is the use of && in *nix, in conditional execution, e.g. ls abc && grep aaa abc. You mentioned that && may not do what one intends. Do you have an example where && does not do what intended? thanks, bliako

        The higher precedence of && can be illustrated by the difference between these two:

        $ perl -E '$foo = 1 && $bar = 3; say $foo' 3 $ perl -E '$foo = 1 and $bar = 3; say $foo' 1

        This is why the word operators ( and or not ) should generally be used for control flow instead of the high-precedence symbolic operators ( && || ! ). HTH.

Re^2: Confused by a couple of idioms
by nysus (Parson) on Feb 21, 2019 at 23:46 UTC

    Ah, I was reading the precedence like this: ($csv and $xls) = $csv;

    I think the lowercase "and" basically makes it act more like this: $csv and ($xls = $csv)

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

      I think the lowercase "and" basically makes it act more like this: $csv and ($xls = $csv)

      Correct. Deparsing makes it even clearer:

      12:28 >perl -MO=Deparse -e "$csv and $xls = $csv;" $xls = $csv if $csv; -e syntax OK 12:29 >

      Hope that helps,

      Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

        Damn, that's crazy. Never knew about that.

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks

      I think the lowercase "and" basically makes it act more like this: $csv and ($xls = $csv)
      Yep. That's basically the entire reason that the and and or operators exist. and and or are low-precedence (making them useful for flow control), while && and || are high-precedence (making them useful for boolean logic). This is why, 99% of the time, open ... or die is correct and open ... || die is wrong.