Print out file line number : File Output « File « Perl






Print out file line number

    


#!/usr/bin/perl -w

use strict;

open(FILE, '<', 'yourFile.txt') or die $!;
my $lineno = 1;

while (<FILE>) {
    print $lineno++;
    print ": $_";
}

close FH;

   
    
    
    
  








Related examples in the same category

1.Print message in case of file open failure
2.Print text to file
3.Prints the size of a file in bytes.
4.Numbering Lines in Multiple Files
5.Output file line by line
6.Output file