hsmyers has asked for the wisdom of the Perl Monks concerning the following question:
Which produces:#!/usr/bin/perl -w # test.pl -- use strict; use warnings; use diagnostics; my @a = ( 'one', 'two', 'three' ); print join("\n",@a),"\n__________\n"; setmode('add_test',@a); print join("\n",@a); sub setmode { my $val = shift(@_); my @a = @_; splice(@a,1,0,$val); $_[$_] = $a[$_] for (0..@a); }
Obviously @_ is an array of aliases and that portion of the direct hands on works as expected. And I've no expectation that there would be anyway to effect what I want short of references. But since TIMTOWTDI, I thought I'd ask if anyone knew a method that would allow me to have my cake and eat it too. Clearly this would work:C:>test one two three __________ one add_test two
but I was looking for a little magic here...sub setmode { my($val,$ref) = @_; splice(@$ref,1,0,$val); }
--hsm
"Never try to teach a pig to sing...it wastes your time and it annoys the pig."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can @_ be extended?
by Mr. Muskrat (Canon) on Feb 11, 2005 at 03:03 UTC | |
|
Re: Can @_ be extended?
by Fletch (Bishop) on Feb 11, 2005 at 02:41 UTC | |
|
Re: Can @_ be extended?
by saskaqueer (Friar) on Feb 11, 2005 at 04:09 UTC | |
|
Re: Can @_ be extended?
by hsmyers (Canon) on Feb 11, 2005 at 07:06 UTC | |
by BrowserUk (Patriarch) on Feb 11, 2005 at 07:28 UTC | |
by hsmyers (Canon) on Feb 11, 2005 at 08:21 UTC | |
by BrowserUk (Patriarch) on Feb 11, 2005 at 08:56 UTC | |
by tphyahoo (Vicar) on Feb 11, 2005 at 13:23 UTC | |
by Ven'Tatsu (Deacon) on Feb 11, 2005 at 15:51 UTC | |
by Tanktalus (Canon) on Feb 11, 2005 at 16:27 UTC | |
|
Re: Can @_ be extended?
by ihb (Deacon) on Feb 11, 2005 at 13:43 UTC |