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.
In reply to Re: Use an incrementing counter as a variable
by thanos1983
in thread Use an incrementing counter as a variable
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |