Here is the problem I need to write a program in PERL that p
Here is the problem:
I need to write a program in PERL that prompts for a CSV file and contains three fields of data. It needs to validate the data, if it is valid data, then it needs to save that field to an XML file, if the data is invalid it needs to give a chance for the user to correct the data. The program can\'t use mods, so it needs to be strictly code.
Any help would be appreciated! I\'m stumped on the CSV to XML coversion without using mods.
Solution
Hello,
please find solution for above problem statement.
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV;
my $file = $ARGV[0] or die \"Need to get CSV file on the command line\ \";
my $csv = Text::CSV->new ({
binary => 1,
auto_diag => 1,
sep_char => \',\' # not really needed as this is the default
});
my $sum = 0;
open(my $data, \'<:encoding(utf8)\', $file) or die \"Could not open \'$file\' $!\ \";
while (my $fields = $csv->getline( $data )) {
$sum += $fields->[2];
}
if (not $csv->eof) {
$csv->error_diag();
}
close $data;
print \"$sum\ \";
