in reply to csv file is not opening using use strict
The problem is in print:
That shouuld beprint "$fields[0] fields[1]";
Note that my @fields should be parenthesized to get a list; also, you opened $data, so don't forget to close it.print "$fields[0] $fields[1]";
#!/usr/bin/perl -l BEGIN { $| = 1; $^W = 1; } use strict; use autodie; use warnings; my $file_c = '/root/Desktop/file1.csv'; open my $data, '<', $file_c or die "Could not open file: $!"; while ( defined( my $line = <$data> ) ) { do { next if ( $. == 1 ); chomp $line; my (@fields) = split( /,/, $line, 0 ); print "$fields[0] $fields[1]"; }; } close $data;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: csv file is not opening using use strict
by chromatic (Archbishop) on Sep 07, 2012 at 01:28 UTC | |
Re^2: csv file is not opening using use strict
by GrandFather (Saint) on Sep 07, 2012 at 01:07 UTC |
In Section
Seekers of Perl Wisdom