cesear has asked for the wisdom of the Perl Monks concerning the following question:
Now my main goal I am trying to accomplish is if @bundle1 is found in @charges, then remove the corresponding @bundle1 in @charges and replaced with 'chx'.use warnings; use strict; my @bundle1 = qw/ch3 ch4 ch6/; my %bundle1 = ( ch3 => 0, ch4 => 0, ch6 => 0, ); my $i = 0; my @charges = qw/ch1 ch2 ch3 ch4 ch5 ch6 ch7 ch8 ch1 ch2 ch3 ch4 ch5 c +h1 ch2 ch6 ch7 ch4 ch3 ch9 ch2 ch4/; foreach my $bundle (@bundle1) { foreach my $charge (@charges) { if ($bundle eq $charge) { $i++; $bundle1{$bundle} = $i; print $bundle1{$bundle}; } } }
So input is--> ch1 ch2 ch3 ch4 ch5 ch6 ch7 ch8 ch1 ch2 ch3 ch4 ch5 ch1 ch2 ch6 ch7 ch4 ch3 ch9 ch2 ch4
So output is--> ch1 ch2 ch5 chx ch7 ch8 ch1 ch2 ch5 ch1 ch2 chx ch7 ch4 ch3 ch9 ch2 ch4
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: array within an array
by toolic (Bishop) on Oct 07, 2011 at 13:49 UTC | |
by wfsp (Abbot) on Oct 07, 2011 at 14:03 UTC | |
by cesear (Novice) on Oct 07, 2011 at 14:16 UTC | |
by aartist (Pilgrim) on Oct 07, 2011 at 15:01 UTC | |
by Lotus1 (Vicar) on Oct 07, 2011 at 14:13 UTC | |
by cesear (Novice) on Oct 07, 2011 at 15:09 UTC | |
Re: array within an array
by aartist (Pilgrim) on Oct 07, 2011 at 14:40 UTC | |
by cesear (Novice) on Oct 07, 2011 at 15:18 UTC | |
by hbm (Hermit) on Oct 07, 2011 at 16:21 UTC | |
Re: array within an array
by Anonymous Monk on Oct 07, 2011 at 20:13 UTC |
Back to
Seekers of Perl Wisdom