I am attempting to parse a CSV, but am not allowed to install the CSV parsing module because of "security reasons" (what a joke), so I'm attempting to use 'split' to break up a comma-delimited file.
My issue is that as soon as an "empty" field comes up (two commas in a row), split seems to think the line is done and goes to the next one.
Everything I've read online says that split will return a null field, but I don't know how to get it to go to the next element and not just skip to the next line.
[code=perl]
while (<INFILE>) {
# use 'split' to avoid module-dependent functionality
# split line on commas, OS info in [3] (4th group, but
# counting starts first element at 0)
# line = <textonly>,<tex t+num>,<ip>,<wh atIwant>,
chomp($_);
@a_splitLine = split (/,/, $_);
# move OS info out of string to avoid accidentally
# parsing over stuff
$s_info = $a_splitLine[3];
[/code]
Could anyone see either a better way to accomplish what I'm trying to do, or help get split to capture all the elements?
I was thinking I could run a simple substitution before parsing of a known string (something ridiculous that'll never show up in my data - like &^%$#), then split, and then when printing, if that matches the current item, just print some sort of whitespace, but that doesn't sound like the best method to me - like I'm overcomplicatin g it.
My issue is that as soon as an "empty" field comes up (two commas in a row), split seems to think the line is done and goes to the next one.
Everything I've read online says that split will return a null field, but I don't know how to get it to go to the next element and not just skip to the next line.
[code=perl]
while (<INFILE>) {
# use 'split' to avoid module-dependent functionality
# split line on commas, OS info in [3] (4th group, but
# counting starts first element at 0)
# line = <textonly>,<tex t+num>,<ip>,<wh atIwant>,
chomp($_);
@a_splitLine = split (/,/, $_);
# move OS info out of string to avoid accidentally
# parsing over stuff
$s_info = $a_splitLine[3];
[/code]
Could anyone see either a better way to accomplish what I'm trying to do, or help get split to capture all the elements?
I was thinking I could run a simple substitution before parsing of a known string (something ridiculous that'll never show up in my data - like &^%$#), then split, and then when printing, if that matches the current item, just print some sort of whitespace, but that doesn't sound like the best method to me - like I'm overcomplicatin g it.
Comment