in reply to Adding items to arrays: best approach?
What's the best/preferred/Perl-ish method?
That will be subjective. However, I'd have to go with push for several reasons perhaps the strongest of which is that this is precisely what it is designed to do: append entries to arrays. If it were no better than the first approach it would not be in the language.
Has the first method advantages over the second method or vice versa? What are the advantages, if any?
I see some advantages to the second method:
That said, I would definitely combine your 4 pushes into one and probably use a glob or map to avoid all the repetition.
What's the habbit in case of initial array declaration and first method: put the comma's at the back or at the front?
Not sure what you mean here, sorry.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Adding items to arrays: best approach?
by geertvc (Sexton) on May 28, 2020 at 12:01 UTC | |
by soonix (Chancellor) on May 28, 2020 at 13:06 UTC | |
by hippo (Archbishop) on May 28, 2020 at 14:12 UTC | |
by jcb (Parson) on May 29, 2020 at 00:09 UTC |