There is probably an easy solution to this, but I can't figure it out. I am looking to:
- take a CSV file into an array
- loop through the array and split fields into variables
- if the array field is empty then set the variable to "N/A"
Note: It is only setting the $variable to "N/A" that I cannot get working.
For example:
foreach $var (@list) {
($name,$date,$size, etc...)=split(/,\"/,$var);
}
How would I set $date to "N/A" if the field in the array is empty?
so to produce:
$name = Jim
$date = N/A
$size = small
I hope this makes sense and is easy to fix. -Thanks
/,\"/smells funny. Do your fields begin with a quote and not end with a quote? Are you stripping a trailing quote from the data after thesplitcall? Does the first field not begin with a quote?