split
Example 7-6. examples/arrays/process_csv_file.csv
Foo,Bar,10,home Orgo,Morgo,7,away Big,Shrek,100,US Small,Fiona,9,tower
Example 7-7. examples/arrays/process_csv_file.pl
#!/usr/bin/perl
use strict;
use warnings;
my $file = 'process_csv_file.csv';
if (defined $ARGV[0]) {
$file = $ARGV[0];
}
my $sum = 0;
open(my $data, '<', $file) or die "Could not open '$file'\n";
while (my $line = <$data>) {
chomp $line;
my @columns = split ",", $line;
$sum += $columns[2];
}
print "$sum\n";
| Prev | Home (Copyright Gabor Szabo) Perl Training Israel | Next |
| Module documentation | Up | process csv file (short version) |