What is the equivalent of NR (awk) in perl?

Hello,

I searched online; it seems that perl use $NR as NR in awk; however it does not work for me. For example, how to re-write the following awk using perl:

awk '{ print NR}' inputfile

---------- Post updated at 01:55 PM ---------- Previous update was at 12:49 PM ----------

I found following perl command will work the same as awk:

perl -MEnglish -lane 'print $NR' inputfile

However, I am wondering, if i am writing a perl script, is there a simple way to denote NR (number of record)?

Try $.

1 Like

For any questions regarding special perl variables, the perlvar man page is the definitive source.

Regards,
Alister

1 Like