I'am a beginner in learning perl.
What I'm trying to do here is to split the array @value and insert it into a new array. my problem is, I do not know exactly how to make my coding to run in loop and get my desired result.
Is it possible to get the desired result using this method or is there any other alternative/way to get the same result?
My code is as below;
my @separated = ();
my @separated1 = ();
my @separated2 = ();
my @separated3 = ();
my $counter = 0;
my @values = "aaa 111 AAA bbb 222 BBB ccc 333 CCC ddd 444 DDD";
foreach (@values) {
my @separated = split(' ', $_);
push @separated1, $separated[0];
push @separated2, $separated[1];
push @separated3, $separated[2];
}
$counter++
print "separated1 = @separated1\n";
print "separated2 = @separated2\n";
print "separated3 = @separated3\n";
Result that I got;
separated1 = aaa
separated2 = 111
separated3 = AAA
Desired Result;
separated1 = aaa bbb ccc ddd
separated2 = 111 222 333 444
separated3 = AAA BB CCC DD


my @values = "aaa 111 AAA bbb 222 BBB ccc 333 CCC ddd 444 DDD"... is assigning one scalar value to an array. It's effectivly putting that scalar value into the first slot of@valuearray. You may do asplithere directly:my @values = split / /, "aaa 111 AAA bbb 222 BBB ccc 333 CCC ddd 444 DDD";Once this is in place, the rest is to take 3 values at a time etc etc.