my $line = ";field;;field;\t;field; ;field;field"; my @line = split ";", $line; my @null = grep { defined $_ } map { $line[$_] =~ /^$/ ? $_ : undef } +(0..$#line); print "line contains ", scalar @null, " null fields at offset(s): @nul +l"; #line contains 2 null fields at offset(s): 0 2
use strict; while ( <DATA> ) { my @line = split /\|/, $_; my @null = grep { defined $_ } map { $line[$_] =~ /^$/ ? $_ : unde +f } (0..$#line); print "line contains ", scalar @null, " null fields at offset(s): +@null\n"; } #line contains 3 null fields at offset(s): 1 3 4 #line contains 2 null fields at offset(s): 2 4 #line contains 3 null fields at offset(s): 0 1 4 #line contains 2 null fields at offset(s): 1 2 4 __DATA__ first||third|| alpha|beta||delta| ||c|d| one|||four|
In reply to Re: identifying null fields in bar delimited records
by holli
in thread identifying null fields in bar delimited records
by jjohhn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |