my @list = qw(a b a a d e e );
I want to compact the array by concatenating the adjacent vowels and consonant together, like for the above it should become,
my @list2 = qw(ab aa d ee);
How do I get the @list2 ? Thanks.
Send instant messages to your online friends http://uk.messenger.yahoo.com
> Hello, my logic is really bad, here is I want to do.
>
> my @list = qw(a b a a d e e );
>
> I want to compact the array by concatenating the adjacent vowels and
> consonant together, like for the above it should become,
>
> my @list2 = qw(ab aa d ee);
>
> How do I get the @list2 ? Thanks.
I think you meant either qw(ab aad ee) or qw(a b aa d ee). In either
case it's easier to start with a string than with an array. Something
like:
@list2 = ('abaadeec' =~ /([aeiouy]*(?:[^aeiouy]|$))/g);
pop(@list2) if $list2[-1] eq '';
or
@list2 = ('abaadeec' =~ /([aeiouy]+|[^aeiouy]+)/g));
pop(@list2) if $list2[-1] eq '';
Depends on what did you actually want, the example you gave makes no
sense to me.
Jenda
===== Je...@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
The program below appears to do what you need.
HTH,
Rob
use strict;
use warnings;
my @list = qw(a b a a d e e );
my @list2 = syllables(@list);
print "(@list2)\n";
sub syllables {
return @_ unless @_ > 1;
my @return;
foreach (@_) {
if ($return[-1] =~ /[^aeiou]$/) {
push @return, $_;
}
else {
$return[-1].= $_;
}
}
@return;
}