Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^2: Confused by a couple of idioms

by rsFalse (Hermit)
on Feb 22, 2019 at 09:31 UTC ( #1230361=note: print w/replies, xml ) Need Help??

in reply to Re: Confused by a couple of idioms
in thread Confused by a couple of idioms

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)

Replies are listed 'Best First'.
Re^3: Confused by a couple of idioms
by bliako (Parson) on Feb 22, 2019 at 11:36 UTC

    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.

        got it thanks.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2020-01-18 12:20 GMT
Find Nodes?
    Voting Booth?