in reply to Use an incrementing counter as a variable

Hello Anonymous Monk,

I think/assume you want to know the line number as you read the file. If so no need to use counters etc, Perl has got your back. Use the perlvar/Variables related to filehandles/$.. Then combine it with a hash as the fellow monks has provided you with several examples.

Sample of code:

#!/usr/bin/perl use strict; use warnings; use feature qw(say); while (<>) { chomp; say $. . "\t" . $_; } __END__ $ perl test.pl test_1.txt 1 Line 1 2 Line 2 3 Line 3

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!