A quick look with B::Terse (hey, I learned a new trick, I'm gonna use it :) ) at this:
my $aryref=[ qw(one two) ]; my @array=@$aryref; my @arraytwo=qw(one two);
Shows this as a result:
LISTOP (0x8115698) leave [1] OP (0x8120b78) enter COP (0x8115658) nextstate BINOP (0x8115630) sassign UNOP (0x81795e0) srefgen UNOP (0x8120cd8) null [141] LISTOP (0x8120340) anonlist OP (0x8120cb8) pushmark SVOP (0x811a068) const PV (0x811d8e4) "one" SVOP (0x81203c0) const PV (0x811d8d8) "two" OP (0x814db90) padsv [1] COP (0x81157d0) nextstate BINOP (0x8115770) aassign [4] UNOP (0x8115728) null [141] OP (0x8115750) pushmark UNOP (0x81156c0) rv2av [3] OP (0x8179600) padsv [1] UNOP (0x81156e0) null [141] OP (0x8115708) pushmark OP (0x81795c0) padav [2] COP (0x8120b38) nextstate BINOP (0x8120b10) aassign [6] UNOP (0x8120a80) null [141] OP (0x8120aa8) pushmark SVOP (0x8120a40) const PV (0x811d908) "one" SVOP (0x8120a60) const PV (0x811d8f0) "two" UNOP (0x8120ac8) null [141] OP (0x8120af0) pushmark OP (0x8115810) padav [5] cloning.pl syntax OK
In other words, the @array=@$aryref does not copy the array members, it just sets up @array to point to the data pointed to by $aryref (and increases said data's refcount). Perl does the right thing here. So, you should not expect a performance penalty for this. You should still have some penalty (notably, pointing the new array's members to the SV's), but not the same as creating a full blown array from the ground up. Ah well, rv2av is apparently a full blown copy. Never mind my blabbering. Thanks chromatic and PodMaster.

However, I would try and get used to the 'ugly syntax' of references and dereferencing them - they are among the most powerful features of Perl and are the only way of building complex data structures. You will need them :)

Update: Stopped lying. :)

CU
Robartes-


In reply to Re: Converting an Array Reference into an Array by robartes
in thread Converting an Array Reference into an Array by NetWallah

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.