This is probably a dumb question. I am trying to take a list of @num_weights and add one number from @leftovers to the front, save it in a @hold_generations array, for all @leftovers. The code is:
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); }
However, I am getting this result from Dumper()
$VAR1 = [ 1, 2, 3, 4 ]; $VAR2 = [ 36, 264, 188 ]; $VAR1 = [ 1, 2, 3, 4 ]; $VAR2 = [ 36, 264, 188 ]; $VAR1 = [ 1, 2, 3, 4 ];
Shouldn't Var1 be 1,36,264,188? That's whay I'm trying to get!

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.


In reply to Troubles with Unshift and Push by nat47

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.