Newbie95 has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: join string in 2D array
by roboticus (Chancellor) on May 03, 2019 at 12:13 UTC | |
Re: join string in 2D array
by Anonymous Monk on May 03, 2019 at 10:52 UTC | |
Re: join string in 2D array
by Marshall (Canon) on May 04, 2019 at 20:46 UTC | |
by AnomalousMonk (Archbishop) on May 05, 2019 at 00:51 UTC | |
by Marshall (Canon) on May 05, 2019 at 03:48 UTC |
Back to
Seekers of Perl Wisdom