Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Print Line number as script runs..

Reply
Thread Tools

Print Line number as script runs..

 
 
Joe
Guest
Posts: n/a
 
      11-19-2007
All,

Is there a special variable for current line number as the script
runs?
Using this for debugging as script is executed..

maybe append this with "die" or "warn" to give me a line number.

ex.

#########
/usr/bin/perl -w
use strict;
my $line = "<some magic variable>";
print " CURRENT LINE: \"$line\"\n";
exit;
#########


Joe
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      11-19-2007
Joe wrote:
> Is there a special variable for current line number as the script
> runs?
> Using this for debugging as script is executed..


You seem to be looking for __LINE__

> maybe append this with "die" or "warn" to give me a line number.


die() and warn() print the line number if the last string you pass to
them does not end with "\n".

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Joe
Guest
Posts: n/a
 
      11-19-2007
On Mon, 19 Nov 2007 02:48:26 +0100, Gunnar Hjalmarsson
<(E-Mail Removed)> wrote:

>Joe wrote:
>> Is there a special variable for current line number as the script
>> runs?
>> Using this for debugging as script is executed..

>
>You seem to be looking for __LINE__
>
>> maybe append this with "die" or "warn" to give me a line number.

>
>die() and warn() print the line number if the last string you pass to
>them does not end with "\n".



Thanks..

I have a few scripts over 15000 lines.. Here recently it's starting to
poke it's head..
 
Reply With Quote
 
brian d foy
Guest
Posts: n/a
 
      11-20-2007
In article <(E-Mail Removed)>, Joe
<(E-Mail Removed)> wrote:

> All,
>
> Is there a special variable for current line number as the script
> runs?
> Using this for debugging as script is executed..


You want something like Devel::Trace, which prints out each line before
it's executed. Instead of printing each line, however, modify the
source to print out the line number.

See my article on creating Perl debuggers:

http://www.ddj.com/184404522

or check out the stuff on the DB::* namespace in perldebug.

Good luck
 
Reply With Quote
 
jl_post@hotmail.com
Guest
Posts: n/a
 
      11-20-2007
On Nov 19, 7:16 pm, brian d foy <(E-Mail Removed)> wrote:
>
> See my article on creating Perl debuggers:
>
> http://www.ddj.com/184404522



Thank-you for sharing that. I found it really useful.

I never knew about "ptkdb" before now. Now I can debug my programs
graphically with "perl -dtkdb script.pl" on my ActiveState Perl
distribution (provided I first install ptkdb with "ppm install Devel-
ptkdb").

Thanks again, brian.

-- Jean-Luc Romano
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
print a vs print '%s' % a vs print '%f' a David Cournapeau Python 0 12-30-2008 03:19 AM
Problem - I want to print Current Output of Pdf file and should print once.I get print dialog box but it is not working keto Java 0 05-30-2007 11:27 AM
How to print a 32-bit number as a base-10 number Steve C Programming 5 12-13-2004 07:07 PM
Read a file line by line with a maximum number of characters per line Hugo Java 10 10-18-2004 11:42 AM
Unlarging the print to print using PDF file to print Bun Mui Computer Support 3 09-13-2004 03:15 AM



Advertisments