Hi,
I wanted to append two subsequent characters (non *) in
an array and then storing them into new array.
But then I also want to restore the '*' string in its
initial position in the new array result.

I have the code below but still not
achieving the task.
How can I modify them so that I can get
it to return result as stated in the example below?


__BEGIN__
#!/usr/bin/perl -w
use strict;
use Data::Dumper;

                                          # For first elem
                                          #    BA also acceptable
my @array   = ('A','B','*','C');  # returns: ['AB', 'BA','*','CB']
my @array1  = ('*','A','B','C');  # returns: ['*',  'AB','BA','CB']
my @array2  = ('A','B','C','*');  # returns: ['AB', 'BA','CB','*']
my @array3  = ('A','B','C','D');  # returns: ['AB', 'BA', 'CB','DC']

my @result = get_array(@array);
print Dumper [EMAIL PROTECTED] ; # See above ('returns') for the desired result

sub get_array{

     my @array = @_;
     my @result;
     foreach  ( 0 .. $#array-1  )
     {
       my $st = $array[$_+1].$array[$_];
       push @result, $st;
     }
   return @result;
}

__END__

Thanks and hope to hear from you again.

--
Regards,
Edward WIJAYA
SINGAPORE

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to