Hi all. I wanted to know if it's possible to join string inside the 2D array and store it into 1D array. I know if it's 1D array you can store it in the scalar variable but does this work for 2D array? Here is my code:

use warnings; use strict; use Data::Dumper qw(Dumper); my $clk_new; my @clk_new; my @clk = ('ux_prim_clk', 'ux_side_clk', 'ux_xtal_frm_refclk'); my @clk_output = map [ split /_/, $_ ], @clk; print Dumper \@clk_output; for ( my $c= 0; $c<= $#clk_output; $c++) { for ( my $d = 0; $d <= $#{$clk_output[$c]}; $d++ ) { $clk_new = join '_', $clk_output[$c]; print Dumper $clk_new; push @clk_new, $clk_new; } } print Dumper @clk_new;

When i print this, it will give me this output:

$VAR1 = [ [ 'ux', 'prim', 'clk' ], [ 'ux', 'side', 'clk' ], [ 'ux', 'xtal', 'frm', 'refclk' ] ]; $VAR1 = 'ARRAY(0x619920)'; $VAR1 = 'ARRAY(0x619920)'; $VAR1 = 'ARRAY(0x619920)'; $VAR1 = 'ARRAY(0x625700)'; $VAR1 = 'ARRAY(0x625700)'; $VAR1 = 'ARRAY(0x625700)'; $VAR1 = 'ARRAY(0x6929a0)'; $VAR1 = 'ARRAY(0x6929a0)'; $VAR1 = 'ARRAY(0x6929a0)'; $VAR1 = 'ARRAY(0x6929a0)'; $VAR1 = 'ARRAY(0x619920)'; $VAR2 = 'ARRAY(0x619920)'; $VAR3 = 'ARRAY(0x619920)'; $VAR4 = 'ARRAY(0x625700)'; $VAR5 = 'ARRAY(0x625700)'; $VAR6 = 'ARRAY(0x625700)'; $VAR7 = 'ARRAY(0x6929a0)'; $VAR8 = 'ARRAY(0x6929a0)'; $VAR9 = 'ARRAY(0x6929a0)'; $VAR10 = 'ARRAY(0x6929a0)';

I want to store back this array to be like this:

my @clk_new =  ('ux_prim_clk', 'ux_side_clk', 'ux_xtal_frm_refclk');

May I know if my method is wrong? Thank you in advance.


In reply to join string in 2D array by Newbie95

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.