in reply to I cannot believe I'm asking a question about split
split does use a regex, as the second parameter passed to it. That being said, perhaps a regex with a capture will effectively propagate an array for you, sans the 'extra characters:'
use Modern::Perl; use Data::Dumper; my $a = 'a,b,c,d,,,,,,,'; my @col = $a =~ /([^,]+)/gi; say Dumper \@col;
Output:
$VAR1 = [ 'a', 'b', 'c', 'd' ];
However, if you know the number of columns and want to limit split to those, you can do the following:
use Modern::Perl; use Data::Dumper; my $a = 'a,b,c,d,,,,,,,'; my @col = ( split ',', $a, )[ 0 .. 3 ]; say Dumper \@col;
Output:
$VAR1 = [ 'a', 'b', 'c', 'd' ];
Hope this helps!
Update: my @col = split /,+/, $a; produces the same output as both examples above.
|
|---|