http://qs321.pair.com?node_id=700651


in reply to split line

When you're splitting on any whitespace, you want to use \s+ instead of " ". For example:

#!/usr/bin/perl -w use strict; my $line = " 0 10 9 4 1 0 0 0 2 2 1 1 0"; my @config = split /\s+/, $line; for (@config) { next unless $_ =~ /\w+/; print $_, "\n"; }
which has the output:

C:\Code>perl split_num.pl 0 10 9 4 1 0 0 0 2 2 1 1 0
Please note that with leading whitespace in $line, the first element returned by split won't contain any text, so you have to trap for that.