Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^2: Logical Not and arguments to grep

by tangent (Priest)
on Apr 01, 2012 at 20:50 UTC ( #962930=note: print w/replies, xml ) Need Help??

in reply to Re: Logical Not and arguments to grep
in thread Logical Not and arguments to grep

Thanks chromatic, that explains it. I've never really considered the comma as an "operator" but will do from now.
  • Comment on Re^2: Logical Not and arguments to grep

Replies are listed 'Best First'.
Re^3: Logical Not and arguments to grep
by chromatic (Archbishop) on Apr 01, 2012 at 21:19 UTC
    I've never really considered the comma as an "operator" but will do from now.

    Neither did I for many years. Once you really understand how lists work in Perl (and why some people call the comma "the list operator"), then you understand enough about Perl's precedence and associativity that this sort of thing never trips you up much again.

    Working through the exercises in the first chapter of Structure and Interpretation of Computer Programs (and working on a couple of parsers and compilers) cemented this knowledge for me. Fortunately, there's a shortcut: just remember that your computer prefers to do one thing at a time. Not everything can happen at once. There's a sequence to which operations happen.

    Once you get that, you can reason your way to the need for associativity and precedence.

Re^3: Logical Not and arguments to grep
by Marshall (Abbot) on Apr 02, 2012 at 01:02 UTC
    I also prefer to use the block form of map and grep.

    The comma operator is useful in other ways..see the command loop I coded at Re: Storing 10 numbers in array. In the statement,

    while ( (print "$prompt: "), $number = <STDIN> ) {...}
    The comma operator allows this to be a single statement.
    You can't put two statements like:
    print "$prompt"; $number = <STDIN>;
    into the while() conditional. But this statement which uses the comma operator is ok. The "truth or falseness" of the statement is decided by the last clause (the input of the data - not the return value of the print which will be a "1"). Note the paren's are required.

    By doing it this way, a re-prompt happens automatically at every loop iteration without having to code the prompting statement within the loop (and having a standalone initial prompting statement before the loop to get things started).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://962930]
[james28909]: everything past the first two things you piked from my posts are irrelevant to me and my beliefs. they are side effects.
[james28909]: two or three. if it has to do with how humans are handling said situations, then that is after they were able to evolve into those problems. agnostic means only believe with evidence. i took that from a tyson video
[james28909]: and it seems that racism suggest that there is indeed a better race, but that is for evolution to decide
[1nickt]: "right now, humans are smarter than in any of those times": define "smart"
[erix]: ah, now you're appraoch downvote-territory ;)

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2017-12-15 14:57 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (433 votes). Check out past polls.