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


in reply to Re: split line
in thread split line

this works except for the first element, the first element still gets blank. Is there any way to chomp the begining?

Replies are listed 'Best First'.
Re^3: split line
by Your Mother (Archbishop) on Jul 28, 2008 at 21:44 UTC

    dwm042's answer below does this but there's a shortcut specifically for this kind of thing. Try this:

    my $line = " 0 10 9 4 1 0 0 0 2 2 1 1 0"; my @config = grep /\S/, split / /, $line; # or even my @config = grep /\A\d+\z/, split / /, $line; print join(", ", @config), "\n";

    The second will only pass through numbers (well, positive integers and zero) so something like "6a" will be skipped.

Re^3: split line
by gaal (Parson) on Jul 28, 2008 at 21:38 UTC