in reply to splitting every element of an array

Build an array of arrays:
my @segments = map [split //], @genome;

Now $segments[$i] will be a reference to an array containing the chars of $genome[$i], so you can access individual chars with $segments[$i][$j] (where $i is the segment index and $j is the part number), or the entire array of chars of one segment with @{$segments[$i]}.

For example, this code:

my @genome = ("abc", "def", "ghijkl"); my @segments = map [split //], @genome; for my $seg (@segments) { print "Segment: @$seg\n"; }
will output:
Segment: a b c Segment: d e f Segment: g h i j k l

See perldoc perllol for more details.

•Update: a few corrections and a bit more explanation

Replies are listed 'Best First'.
Re: Re: splitting every element of an array
by MarkM (Curate) on Feb 26, 2003 at 05:55 UTC

    I believe the original poster asked for a more efficient means of doing the split, not a method of doing the split using neater code. I'm certain that Benchmark.pm would show your code executing slower than the original.

    UPDATE: After reading the original in the context of the responses to this node, I think I agree that the original poster meant effective not efficient. As in, "what is a more effective method of writing this code?"

      On the other hand, my impression of the OP was that the person was looking for a more efficient way to write the code -- they weren't really concerned with runtime benchmarks, but rather with how to make the code both flexible and compactly written, allowing it to handle an array of any size without making it bulkier. This is often a more important sense of "efficiency". No problem with xmath's answer in this respect.
        That is also the impression I had