Yes, you can write it with @copy and returning it as \@copy. But I prefer using $copy, for symmetrical reasons. I start out with a reference to an array, so if I copy it, I'd like to copy to another reference. But that's just personal preference, I don't one way is significantly faster or easier to understand than the other.
As for copying using a map instead of the double loop is mostly because it's less verbose. It's just one line and I see immediately it's a copy of a 2D array - the double loop takes more lines, and too large to immediately see what it does. I haven't benchmarked it, but if there's a difference I expect the difference to be small, and the map to be slightly faster; with the difference slowly growing if the arrays get larger. But speed isn't my main reason to copy it using a map.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.