in reply to But I want null values in my array
I agree with my learned brethren that a module such as Text::CSV_XS would be the best practice way to go here. However, for an example of how to do this otherwise and assuming that you really do want undef when you say "null", here is an SSCCE.
use strict; use warnings; use Test::More tests => 2; my $have = '1,,3,4,,,'; my @want = (1, undef, 3, 4, undef, undef, undef); my @try = map { length ($_) ? $_ : undef } split (',', $have, -1); is_deeply \@try, \@want, 'Array is correct'; # Your criterion my $count = 0; foreach (@try) { ++$count; } is $count, 7, 'Count is correct';
|
|---|