R
Richard S Beckett
Guys,
I have a line of text like this " 5 6 0 7 176
0". i.e. 9 spaces before the 5.
When I try to place the numbers into an array with split (my @temp = split
(/\s*/, $input)
, I get a blank element at the start. What am I doing
wrong?
Thanks.
=-=-=-=-=-=-=-=-=-=-
use strict;
use warnings;
my $line = " 5 6 0 7 176 0";
my @array = split (/\s*/, $line);
print "Starting...\n";
foreach (0..$#array) {
print "element $_ = $array[$_]\n";
}
print "Finished.\n";
=-=-=-=-=-=-=-=-=-=-
OUTPUT:
Starting...
element 0 =
element 1 = 5
element 2 = 6
element 3 = 0
element 4 = 7
element 5 = 1
element 6 = 7
element 7 = 6
element 8 = 0
Finished.
I have a line of text like this " 5 6 0 7 176
0". i.e. 9 spaces before the 5.
When I try to place the numbers into an array with split (my @temp = split
(/\s*/, $input)
wrong?
Thanks.
=-=-=-=-=-=-=-=-=-=-
use strict;
use warnings;
my $line = " 5 6 0 7 176 0";
my @array = split (/\s*/, $line);
print "Starting...\n";
foreach (0..$#array) {
print "element $_ = $array[$_]\n";
}
print "Finished.\n";
=-=-=-=-=-=-=-=-=-=-
OUTPUT:
Starting...
element 0 =
element 1 = 5
element 2 = 6
element 3 = 0
element 4 = 7
element 5 = 1
element 6 = 7
element 7 = 6
element 8 = 0
Finished.