in reply to Passing arrays in subs

Well, I think you're doing just fine ... If you want to use a reference as suggested, then that's fine ... if you don't want to .. it's up to you.

A simple fix to your code requires changing 2 lines only

#Change my $sItem = @_; my $nItem = @_; # to my $sItem = pop @lsList; my $nItem = pop @lsList;
Not Tested, but should work

Replies are listed 'Best First'.
Re^2: Passing arrays in subs
by lostjimmy (Chaplain) on Jul 30, 2010 at 18:38 UTC
    That doesn't really fix anything. The lexically scoped array will be altered, but the original array, @hello, won't end up with those changes in the main scope. speedyshady needs to use a reference, like morgon and kennethk have already said.

    Alternatively, your method could be used, but the new list would have to be returned.

      That doesn't really fix anything. The lexically scoped array will be altered, but the original array, @hello

      I've never seen the OP message saying "The original array should be changed"

      I've seen him creating a new array, but having difficultly to get the other variables values correct.

      So while others assumed he want to change the original array, I assumed he wants to create a new one ... what's wrong with that ... and what's all that -- for?

Re^2: Passing arrays in subs
by speedyshady (Novice) on Jul 31, 2010 at 00:22 UTC

    I've decided that this is the easiest and best approach for the functionality of the larger picture. I don't want to call-by-reference, so brute-force seems to get the job done. After all, I'm really just rewriting the splice sub

    Also, thanks to everyone else, too because I actually learned a lot about assignments and passing of variables in Perl. Kinda tricky, but it makes sense.