in reply to identifying null fields in bar delimited records
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|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: identifying null fields in bar delimited records
by wfsp (Abbot) on May 31, 2005 at 12:07 UTC | |
by lupey (Monk) on May 31, 2005 at 12:38 UTC | |
by wfsp (Abbot) on May 31, 2005 at 12:50 UTC | |
by holli (Abbot) on May 31, 2005 at 12:53 UTC | |
by jjohhn (Scribe) on May 31, 2005 at 14:04 UTC | |
|
Re^2: identifying null fields in bar delimited records
by Anonymous Monk on May 31, 2005 at 14:01 UTC |