Oooooohhhh, but that builds up an entire list for the slicing and can damage performance horrendously:

#!c:/perl/bin/perl -w $|++; use strict; use Benchmark 'timethese'; # make it so we split() into many many elements our $baz = join '', "yes.no.maybe.so." x 5000; timethese(2000, { undef => q{ ($foo, undef, $bar) = split(/\./, $baz); }, splice => q{ ($foo, $bar) = (split(/\./, $baz))[0,2]; } } ); __END__ Benchmark: timing 2000 iterations of splice, undef... splice: 101 wallclock secs (93.86 usr + 0.39 sys = 94.25 CPU) @ +21.22/s (n= 2000) undef: 0 wallclock secs ( 0.14 usr + 0.00 sys = 0.14 CPU) @ 14 +184.40/s ( n=2000) (warning: too few iterations for a reliable count)

In reply to Re^5: Returning first element of an array from a function by Anonymous Monk
in thread Returning first element of an array from a function by lcanty

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.