speedyshady has asked for the wisdom of the Perl Monks concerning the following question:
I'm writing a function that needs to take in an array and then splice it to insert an item into the array. Conceptually this should be very simple to do, however I'm having issues with the array and @_ or any other parameter array or variables.
This needs to produce "Hello World ! BANG!"
my @hello = ("Hello", "World", "BANG!"); sub ListInsert { my @lsList = @_; my $sItem = @_; my $nItem = @_; splice(@lsList, $nItem, 0, $sItem); print "@lsList\n"; } ListInsert(@hello, 2,"!");
But this prints "Hello World BANG! 2 ! 5" Any ideas?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing arrays in subs
by kennethk (Abbot) on Jul 30, 2010 at 17:59 UTC | |
|
Re: Passing arrays in subs
by morgon (Priest) on Jul 30, 2010 at 17:57 UTC | |
|
Re: Passing arrays in subs
by ahmad (Hermit) on Jul 30, 2010 at 18:18 UTC | |
by lostjimmy (Chaplain) on Jul 30, 2010 at 18:38 UTC | |
by ahmad (Hermit) on Jul 30, 2010 at 19:20 UTC | |
by speedyshady (Novice) on Jul 31, 2010 at 00:22 UTC |