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

Yeah, say Dumper(@num_weights)shows whats in the array.

Replies are listed 'Best First'.
Re^3: Troubles with Unshift and Push
by vinoth.ree (Monsignor) on Mar 04, 2015 at 05:27 UTC

    But it creates array with one element with anonymous array.


    All is well. I learn by answering your questions...
      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...