On Tue, 20 Aug 2002 11:12:31 +0200 (MEST), Louis Pouzin wrote:
>When debugging scripts it'd be nice to:
> print $LN, $somedata;
>where $LN is the line number of the print statement.
>
>There doesn't seem to be a special variable for the line number. Or is there an other
>trick ?
I know of two (or three).
First is the __LINE__ "macro". You should make sure perl doesn't mistake
it for a filehandle, for example using
print +__LINE__, " This is my data\n";
Second is to call a sub, which, through caller(), can determine which
line it's been called from.
sub ln {
return join " ", (caller)[1, 2];
}
print ln, " this is line 8";
-->
test.pl 8 this is line 8
Or 3: just use warn() instead of print. ;-)
--
Bart.