Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: splicing two arrays together

by GrandFather (Cardinal)
on Jan 06, 2012 at 06:22 UTC ( #946533=note: print w/ replies, xml ) Need Help??


in reply to Re: splicing two arrays together
in thread splicing two arrays together

This is a trivial variant of one of the three different splice based options I provided. So which of the trivial variations is "the one best way" to do it? How is this "the best way" if preserving the content of @first is desired? What non-artificial context would require the use of split?

Remember an oft quoted virtue of Perl is TIMTOWTDI with the strong implication that there is seldom a "single best solution". Actually even with languages that tout themselves as offering the "one true way" there is seldom a single "best" solution to any problem.

True laziness is hard work


Comment on Re^2: splicing two arrays together
Re^3: splicing two arrays together
by Anonymous Monk on Jan 06, 2012 at 08:51 UTC
    Thanks Grandfather for those solutions, the best solution I guest is the one that requires the least amount of typing in any language?
      Well, it depends. The best solution might be the one that runs fastest, uses minimal memory, or the one that can be easily understood for later maintenance.

      I'd say the best solution is the one that works correctly, is maintainable and fast enough. Number of lines or characters of code is generally one of the least important criteria. The most important criteria depends a great deal on the purpose of the code.

      True laziness is hard work
Re^3: splicing two arrays together
by TJPride (Pilgrim) on Jan 06, 2012 at 20:58 UTC
    Actually, it's an independent solution that just happens to be mostly identical to yours. My determination of "best" is that the OP asked for a solution with splice, and this was the best solution possible with splice. Obviously, splice is not the most efficient way to do this overall, but that's the OP's problem, since he framed the question in the context of splice rather than the context of finding the most efficient way to do merge two arrays. I'm guessing it's a homework problem and they said he had to use splice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2014-09-23 20:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls