I am reading file contents in perl by following code
my @files = glob("$PATH/*");
foreach my $file (@files){
open(MYFILE,"<$file");
my @fileContent = <MYFILE>;
close(MYFILE);
}
Now, I want to prepend auto-incrementing number to each line. Something like —
fileContent[0] = 1: This
fileContent[1] = 2: is
fileContent[2] = 3: a
fileContent[3] = 4: text
fileContent[4] = 5: file.
Does someone know an efficient way to do it?
Thanks!
How about a one-liner?
Or inside a script, with an array:
Documentation on
$.here.