Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Determining what line a filehandle is on

by snafu (Chaplain)
on Jul 06, 2001 at 01:52 UTC ( #94300=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://94300]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2021-11-29 13:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?