(Sorry for the hype, I'm just testing catch words :-)
Technique to get references to selected elements of an ARRAY. Have you ever wanted to manipulate just a few elements of an array without undue copying? I came across this construct \($x,$y,$z) referenced in the DBI documentation, which yields three scalar references to each of the variables in parentheses and I thought, hmmmmmm, I wonder if you could apply this to an array, so I tried it and violin! worked.
Say your ripping through a file and splitting the lines on tabs. An you want to modify fields 3,5 & 7 (0 based of course) you can:
($a,$b,$c) = \(@array[3,5,7]);
after which you can do things like:
$$a =~ s/^\s+//; # remove leading white space from $array[3] $$b =~ s/\s+$//; # and trailing ws from $array[5] $$c++; # incremnt $array[7]
assigning to an array also works:
@y = \(@array[2..4,9]);

Maybe not hard to write, maybe a little obscure, but definitely very handy.

www.taxax.org


In reply to Free, explosive, fun, thrill-packed, exciting adventure by methodius

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.