Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get program line number? 1

Status
Not open for further replies.

TonyGroves

Programmer
Aug 13, 2003
2,389
IE
Does anybody know how to get the current Perl source file line number?

Thanks.
 
What do you mean by current source file line number? Can you give an example? Is is gonna be used for debugging code?
you can put warning messages on the lines you want to check, if this is the reason.
Something like this maybe?
Code:
#!/usr/bin/perl -w
$foo=6;
if ($foo gt 5){
   print "It works\n"; warn " ";
}


OUTPUT
--------
It works
 at - line 3.
But I'm not sure if I this is what you want! Is it?


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
If you've got an error, perl gives that in the output

looking here doesn't seem there is one

try using warning statements to trace the right line number would be one idea

Code:
use CGI::Carp qw /fatalsToBrowser/;
{...
   Block1
...} warn "completed block 1";
...

HTH
--Paul

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
you can use __LINE__ but nobody here, including me, knows what you want to do.
 
Thanks for all the replies and sorry for not responding sooner, but I was asleep in bed, it's something I do every night. __LINE__ does exactly what I'm looking for. The star goes to KevinADC.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top