'How do I list the line number of a file with a Perl script? [duplicate]
I've made a Perl script to list the contents of a specified file, but I also want to see the line number of the file content. What functions in Perl enable this?
This is my code:
#!/usr/local/bin/perl
use warnings;
use strict;
print "Specify the file you want to look at:\n";
my $file_name = <STDIN>;
chomp $file_name;
open(FH, '<', $file_name) or die "Cannot open $file_name: $!";
print "This is the listed content of: $file_name\n";
while(<FH>){
print $_;
}
close(FH);
This is what happens when I run the script, and this is what I would like it to do.
Actual result Wished result
Hello 1. Hello
my 2. my
name 3. name
is 4. is
Janne 5. Janne
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
