in reply to Joining Two Elements of an Array. Little Help Please.
When posting code, a complete description including sample input/output is helpful. See How do I post a question effectively?. Independent of that, I can identify a few problems with your posted code snippet.
So taking all this into account, a working version of your code might look like:
use strict; use warnings; use Data::Dumper; my @sorted = qw(1.2.3 a.b.c literal.b.c); my @array1; my @array2; my @array3; foreach my $results (@sorted) { + my @listOfItems = split( /\./, $results); if ( $listOfItems[0] =~ /literal/ ) { $listOfItems[0] = join(".", @listOfItems[0..1]); + } push (@array1, $listOfItems[0]); push (@array2, $listOfItems[1]); push (@array3, $listOfItems[2]); # @array1 should contain the newly conjoined $listOfItems[0] } print Dumper \@array1;
You may find a read through of Basic debugging checklist helpful -- it's quite useful for demonstrating how to track all of the above issues down.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Joining Two Elements of an Array. Little Help Please.
by ishootperls (Novice) on Sep 27, 2012 at 21:38 UTC |