in reply to Re^2: Troubles with Unshift and Push
in thread Troubles with Unshift and Push

But it creates array with one element with anonymous array.


All is well. I learn by answering your questions...

Replies are listed 'Best First'.
Re^4: Troubles with Unshift and Push
by nat47 (Sexton) on Mar 04, 2015 at 05:30 UTC
    Sorry, I'm new to Perl and I don't know what you're saying. When say Dumper(@num_weights) is said, shouldn't it show
    [1, 36, 264, 188 ];
    ?
      Sorry, I'm new to Perl and I don't know what you're saying

      Reading this node Arrays: A Tutorial/Reference will help you better learning.

      Here is the code I did some changes in your code try and let me know.

      use strict; use warnings; use Data::Dumper; my @num_weights = (36,264,188); my @leftovers = (1,2,3,4); my @hold_generations; my $i = 0; for(my $p = 0; $p < 1;$p++) #Go through all leftovers { my $pick = $leftovers[$p]; unshift @num_weights, $pick; #add item print Dumper(\@num_weights); push @hold_generations, @num_weights; #store new array print Dumper(\@hold_generations); splice @num_weights, 1, 1; #undo adding item print Dumper(\@num_weights); }

      Note:

      I do not have features module so I just used print()


      All is well. I learn by answering your questions...
        This worked perfectly! I'm looking over it now to try and see the differences. Thank you so much.

        I've actually been referencing that today :crying face:

        EDIT: I'm confused... it looks exactly the same? EDIT2: () vs []? I feel like a moron.