Date sent: Wed, 16 Apr 2008 21:47:20 -0700 (PDT) From: anthony brooke <[EMAIL PROTECTED]> Subject: Concatenate similar data in array To: beginner perl mailling list <beginners@perl.org>
> 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 ===== [EMAIL PROTECTED] === 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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/