Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Want to know Line number of the input file

by marto (Cardinal)
on Feb 24, 2016 at 12:08 UTC ( [id://1156006]=note: print w/replies, xml ) Need Help??


in reply to Want to know Line number of the input file

$. perlvar:

test.txt:

line 1 line 2 line 3 line 4 line 5 line 99

ln.pl:

#!/usr/bin/perl use strict; use warnings; open(my $fh, "<", "test.txt") or die "cannot open < test.txt: $!"; while (my $row = <$fh>) { chomp $row; # do something print "line number $.\n"; }

output:

line number 1 line number 2 line number 3 line number 4 line number 5 line number 6

update: forgot to add the output.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1156006]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-03-28 14:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found