nat47 has asked for the wisdom of the Perl Monks concerning the following question:
However, I am getting this result from 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 say Dumper(@num_weights); push @hold_generations, @num_weights; #store new array say Dumper(@hold_generations); splice @num_weights, 1, 1; #undo adding item say Dumper(@num_weights); }
Shouldn't Var1 be 1,36,264,188? That's whay I'm trying to get!$VAR1 = [ 1, 2, 3, 4 ]; $VAR2 = [ 36, 264, 188 ]; $VAR1 = [ 1, 2, 3, 4 ]; $VAR2 = [ 36, 264, 188 ]; $VAR1 = [ 1, 2, 3, 4 ];
I'm sure there is a better way to do this, but I'd really just like to know whats going on.
My goal is to use bigger data sets and later on check @hold_generations for specific instances and then use that instance to re-run this whole thing.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Troubles with Unshift and Push
by vinoth.ree (Monsignor) on Mar 04, 2015 at 05:18 UTC | |
by nat47 (Sexton) on Mar 04, 2015 at 05:19 UTC | |
by vinoth.ree (Monsignor) on Mar 04, 2015 at 05:27 UTC | |
by nat47 (Sexton) on Mar 04, 2015 at 05:30 UTC | |
by vinoth.ree (Monsignor) on Mar 04, 2015 at 05:31 UTC | |
| |
|
Re: Troubles with Unshift and Push
by ipherian (Novice) on Mar 04, 2015 at 23:49 UTC |