Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: why not listed foreach and if?

by harangzsolt33 (Deacon)
on Feb 01, 2025 at 22:58 UTC ( [id://11163904]=note: print w/replies, xml ) Need Help??


in reply to why not listed foreach and if?

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^2: why not listed foreach and if?
by GrandFather (Saint) on Feb 02, 2025 at 04:59 UTC

    In JavaScript the ';' is not required and a human parsing JavaScript can easily misunderstand how the code will be interpreted if they are used.

    In Perl I do:

    if (condition) { ... }

    unless both the condition and the statement (note - just one statement) are simple and short. Perl allows me to use either construct.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
Re^2: why not listed foreach and if?
by marto (Cardinal) on Feb 02, 2025 at 08:15 UTC

    "I am surprised that Perl requires me to put the statement in front of if rather than after. For me, it would be more logical to put the statement after in this case"

    Except you've posted perl code doing exactly that, if ( condition ) { ... }.

      Assuming that the comment you replied to was serious (rather than satire of the initial post or trolling), I believe that they were referring to JS allowing you to omit the {braces} when it's only a single statement. Perl allows if (condition) {statement;} (with braces) and statement if condition; (no braces with postfix conditional), but not if (condition) statement; (no braces with prefix conditional).

        Actually JavaScript and most C like languages don't see the difference between if (<condition>) <statement> and if (<condition>) <block> because a <block> can go anywhere a <statement> can go. Interestingly, and the point of difference here is, Perl requires a <block> in many places where more Cish languages are happy with just a <statement>.

        Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
Re^2: why not listed foreach and if?
by Anonymous Monk on Feb 02, 2025 at 03:51 UTC
    and with that, you have finally jumped the shark into full sundial mode.
      full sundial mode

      For people being new to perlmonks: [redacted by gods]

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        Don't mention the name!

        The way forward always starts with a minimal test.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2025-06-14 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.