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

print

  __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

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to