Re: A newbie question - line number inside the script
- From: rob.dixon@xxxxxxx (Rob Dixon)
- Date: Wed, 16 Jul 2008 14:12:27 +0100
Amit Koren wrote:
I'm a newbie to Perl, (and to this mailing list) :)
There's a task i was given, in which it is necessary to get the
number of the current executing line/command - inside the script itself.
Can someone assist please ?
The value of __LINE__ is the source file line number where it is placed. For
instance
__LINE__
;
will output '3'.
The built-in function caller() will return a list of three values - the package
name, file name, and file line number of the place where the current subroutine
was called. So
use strict;
use warnings;
test();
sub test { print ((caller)[2]) };
will output '4'.
The value of $. is the number of records read from the last-accessed file handle. So
use strict;
use warnings;
<DATA> for 1 .. 3;
print $.;
__DATA__
a
b
c
d
e
will output '3'.
I hope one of these solves your problem.
Rob
.
- References:
- A newbie question - line number inside the script
- From: Amit Koren
- A newbie question - line number inside the script
- Prev by Date: Re: need help on map function
- Next by Date: Re: Printing special characters
- Previous by thread: RE: A newbie question - line number inside the script
- Index(es):
Relevant Pages
|