Hi reswaran,

I'm assuming you meant push @comb, [$val, @$_] for combine \@rest, $n-1; (please use <code> tags).

I'm not sure what combine is, but I'm going to guess that it's a function that returns a list of array references (to find out more, find out which module combine is coming from and read its documentation). For testing, I'm going to substitute the function call with a plain array.

Then, for will loop over the elements of the list returned by combine and set $_ to each of those values. [ ... ] creates a new array reference. This new arrayref will contain the value $val, followed by the elements of the arrayref which is stored in $_ and dereferenced via @$_.

Here, I've rewritten the for loop in a more verbose but hopefully more clear way:

use warnings; use strict; my $val = "foo"; my @combine = (["bar","quz"],["abc","def"]); my @comb; for my $el (@combine) { push @comb, [$val, @$el]; } use Data::Dumper; print Dumper(\@comb); __END__ $VAR1 = [ [ 'foo', 'bar', 'quz' ], [ 'foo', 'abc', 'def' ] ];

Hope this helps,
-- Hauke D


In reply to Re: Push array by haukex
in thread Push array by reswaran

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.