(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

Replies are listed 'Best First'.
Re: Free, explosive, fun, thrill-packed, exciting adventure
by MeowChow (Vicar) on Jun 05, 2001 at 20:59 UTC
    And you can leave out the parens:
    ($a,$b,$c) = \@array[3,5,7];
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print