Print Line number as script runs..

Discussion in 'Perl Misc' started by Joe, Nov 19, 2007.

  1. Joe

    Joe Guest

    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
     
    Joe, Nov 19, 2007
    #1
    1. Advertising

  2. 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
     
    Gunnar Hjalmarsson, Nov 19, 2007
    #2
    1. Advertising

  3. Joe

    Joe Guest

    On Mon, 19 Nov 2007 02:48:26 +0100, Gunnar Hjalmarsson
    <> 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..
     
    Joe, Nov 19, 2007
    #3
  4. Joe

    brian d foy Guest

    In article <>, Joe
    <> 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 :)
     
    brian d foy, Nov 20, 2007
    #4
  5. Joe

    Guest

    On Nov 19, 7:16 pm, brian d foy <> 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 -d:ptkdb script.pl" on my ActiveState Perl
    distribution (provided I first install ptkdb with "ppm install Devel-
    ptkdb").

    Thanks again, brian.

    -- Jean-Luc Romano
     
    , Nov 20, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hugo
    Replies:
    10
    Views:
    1,322
    Matt Humphrey
    Oct 18, 2004
  2. keto
    Replies:
    0
    Views:
    964
  3. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    363
    David Cournapeau
    Dec 30, 2008
  4. PerlFAQ Server
    Replies:
    0
    Views:
    393
    PerlFAQ Server
    Mar 15, 2011
  5. Replies:
    10
    Views:
    231
    Thomas 'PointedEars' Lahn
    Oct 1, 2007
Loading...

Share This Page