in reply to Determining what line a filehandle is on

I prefer __LINE__

open (FILE, "file.txt"); while(<FILE>){ print "I am on line: ".__LINE__."\n"; } close(FILE);

----------
- Jim

Replies are listed 'Best First'.
Re: Re: Determining what line a filehandle is on
by bhar98 (Scribe) on Jul 06, 2001 at 02:14 UTC
    Actually __LINE__ will return the line of the perl code you are on, not the line of the file opened.
Re: Re: Determining what line a filehandle is on
by Anonymous Monk on Jul 06, 2001 at 04:58 UTC
    silly goose. You know what that does? :) __LINE__ tells what line of CODE you're on, not line of the filehandle :)

    eg

    01: use strict
    02:
    03: print "I am on line ", __LINE__, "\n";
    
    will always print
    "I am on line 3\n"
    
Re: Re: Determining what line a filehandle is on
by snafu (Chaplain) on Jul 06, 2001 at 22:02 UTC
    It appears that I made a grave error in my reading of this post :) and thus was 'punished' for it (I know its not really punishment...Im just being colorful).

    Anyway, I appreciate everyone pointing this lil mistake out to me. I will be more careful in my readings of posts next time. I was in a hurry when I read and replied to this write-up.

    There are times where you just gotta admit your mistakes. Anyway, I hope I didn't cause any confusion to those who are new to Perl. IGNORE MY ANSWER! :) It is NOT correct.

    ----------
    - Jim