Numbering Lines in Multiple Files : File Output « File « Perl






Numbering Lines in Multiple Files

    

#!/usr/bin/perl
use warnings;
use strict;
my $lineno;
my $current = "";
while (<>) {
    if ($current ne $ARGV) {
        $current = $ARGV;
        print "\n\t\tFile: $ARGV\n\n";
        $lineno=1;
    }
    print $lineno++;
    print ": $_";
}

   
    
    
    
  








Related examples in the same category

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