Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Adding items to arrays: best approach?

by geertvc (Sexton)
on May 28, 2020 at 12:01 UTC ( [id://11117400]=note: print w/replies, xml ) Need Help??


in reply to Re: Adding items to arrays: best approach?
in thread Adding items to arrays: best approach?

Hello hippo,

Not sure what you mean here, sorry.

Pls. allow me to clarify:

Chose between
$inputPathPrefix . "/test4.xml",
or
, $inputPathPrefix . "/test4.xml"
when adding items to an array (or something similar).

But seen the majority of the people that answered (really big thank you to all!) I think it's not that relevant anymore, since most - if not all - are in favor of the push way of working.

Nevertheless, it would be interesting to hear from wintered Perl programmers their preferred way, although I realize this might be a matter of personal taste and flavor and as such, be quite subjective...

Best,
--Geert

Replies are listed 'Best First'.
Re^3: Adding items to arrays: best approach?
by soonix (Canon) on May 28, 2020 at 13:06 UTC
    Perl accepts commas before the closing parenthesis/bracket/brace without inserting a (dummy) item, therefore I prefer the comma "after", so that all entries are equal (neither the first nor the last differ).
Re^3: Adding items to arrays: best approach?
by hippo (Bishop) on May 28, 2020 at 14:12 UTC

    This is indeed a purely stylistic concern. Personally, when a line needs to be split around a binary operator I would split after the operator as I think this reinforces the point that the statement isn't finished once the end of the line has been reached. I do this in any language, not just Perl. It was probably taught to me decades ago as a minor technique in aiding clarity and has stayed with me ever since.

    With postfix control operators (if, unless, for etc.) it's the other way round as they are more tightly bound to the subsequent clauses (again, subjective). So I might write:

    print 'Very looooooooooooooooooooooooooooooooooooooooooooooooooooooooo +ooooong non-interpolated string costing $many ', "and another clause from prog $0\n"; # but die 'Loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo +ooooooong exception message' if $OMG_ZOMBIES > $max_zombies_allowable;

      Interestingly, the GNU convention is "When you split an expression into multiple lines, split it before an operator, not after one." but GNU style apparently does not treat commas as operators — those are still left at the end of a line.

      if (($foo && $bar && ...) || ($baz && $quux && ...)) { ... } # but function_call_with_many_lengthy_args (very_long_arg1, very_long_arg2, and_on_and_on_and_on);

      GNU style is specifically for C, but Perl syntax is reasonably similar. I suppose the point is that this really is a matter of style, except in Awk, where if I remember correctly, an operator at the end of a line also implies line continuation; the GNU convention requires backslash-newline in Awk.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2024-04-23 12:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found