#Splitting Lines - Answer to exercise 1

$filename = [0];

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

$i = 5;

while ($line = <FILE>)
{
    $i = $i - 1;

    if ($i >= 0)
    {
        @words = split(" ",$line);

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

Compare with Python


Previous Up Next