Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV;
my $csv = Text::CSV->new();
while (<DATA>) {
chomp;
$csv->parse($_);
my @stuff = $csv->fields();
print "$stuff[3]\t$stuff[7]\n";
}
__DATA__
1,2,3,"4,5",6 ,,,Does yours handle embedded commas?
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV;
my $csv = Text::CSV->new();
while (<>) {
next if ($. == 1);
$csv->parse($_);
my @stuff = ($csv->fields())[0 .. 6];
print join(',', @stuff), "\n";
}
perl csvparse.pl input.csv > output.csv
Yes, you aren't listening (reading?). I've already given you some working code, and shown you how to execute it, which you seem to have ignored. But since you asked for it, here is an itemised breakdown of what's wrong with your code.any ideas where I'm going wrong?
#!/usr/bin/perl -w [red]# 1[/red]
use strict;
use warnings;
use Text::csv; [red]# 2[/red]
my @array;
@array = <stdin> ; [red]# 3[/red]
my $csv = Text::CSV->new(); [red]# 4[/red]
foreach my $var (@array)
{
$csv->parse($_); [red]# 5[/red]
chomp(@array); [red]# 6[/red]
my @array = $csv->fields(); [red]# 7[/red]
shift(@array); [red]# 8[/red]
# delete $array[0]; (this is where I was attempting to remove the first row, however it doesn't work)
print "$var\n" ; [red]# 9[/red]
}
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV;
my $csv = Text::CSV->new();
while (<>) {
next if ($. == 1);
$csv->parse($_);
my @stuff = ($csv->fields())[0 .. [red]6[/red]];
print join(',', @stuff), "\n";
}