SPUG:Split question
Michael R. Wolf
MichaelRunningWolf at att.net
Sat Mar 22 16:21:19 CST 2003
Better illustration of trailing empty fields.....
while ($line = <DATA>) {
chomp $line;
@fields = split /([ ,:])/, $line, -1;
foreach my $field(@fields[grep {$_%2 == 0} 0..$#fields]) {
$field = qq("$field");
}
print join("|", @fields), "\n";
}
__DATA__
comma,separated,line
comma,separated,line,,empty,fields,,,,
colon:separated:line
space separated line
Output:
"comma"|,|"separated"|,|"line"
"comma"|,|"separated"|,|"line"|,|""|,|"empty"|,|"fields"|,|""|,|""|,|""|,|""
"colon"|:|"separated"|:|"line"
"space"| |"separated"| |"line"
--
Michael R. Wolf
All mammals learn by playing!
MichaelRunningWolf at att.net
More information about the spug-list
mailing list