#Splitting Lines - Answer to exercise 2

$filename = [0];

open FILE,"<$filename" or die "Cannot read from $filename: \n";

#skip the header line
$line = <FILE>;

#print our own header
print "Make  Premium(\$)  Insurance_class\n";

#read in the rest of the file
while ($line = <FILE>)
{
    chomp $line;

    @words = split(",",$line);

    print "$words[0]  $words[2]  $words[3]\n";
}

Compare with Python


Previous Up Next