Hi,
I am trying to print an array such that each element is followed by the next one, with a tab character in between, and then a new line, so that:
will be displayed as:
so far my code is:
which is *sort of* working alright, except the result i'm getting with it is
the first three lines are fine, but i don't want it to be "circular" i.e i need to stop it after the last item in the array, hope that makes sense. any tips on how to fix this would be great
I am trying to print an array such that each element is followed by the next one, with a tab character in between, and then a new line, so that:
Code:
@array = ("a", "b", "c", "d");
will be displayed as:
Code:
a b
b c
c d
so far my code is:
Code:
my $i;
my @array = ("a", "b", "c", "d");
my $size = @array;
for ($i = 0; $i < $size; $i++) {
print $array[$i] . "\t" . $array[$i+1] . "\n";
}
which is *sort of* working alright, except the result i'm getting with it is
Code:
a b
b c
c d
Use of uninitialized value in concatenation (.) or string at next_array.pl line 13.
d
the first three lines are fine, but i don't want it to be "circular" i.e i need to stop it after the last item in the array, hope that makes sense. any tips on how to fix this would be great