Path: utzoo!attcan!uunet!snorkelwacker!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: wishlist: current line number variable Message-ID: <8812@jpl-devvax.JPL.NASA.GOV> Date: 20 Jul 90 16:53:56 GMT References: <1131@etnibsd.UUCP> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 34 In article <1131@etnibsd.UUCP> vsh@etnibsd.UUCP (Steve Harris) writes: : When the "warn" or "die" function is executed, a message is written to : STDERR which includes the current line number of the perl script. Is : there any way to access this number -- i.e., is there a special perl : variable (or compile-time hook) which evaluates to the current line : number of the perl script? : : Such a feature would be useful for writing one's own warn or die : subroutines. There's no way to do that currently that I know of, short of a massive kludge. (As in, pipe your STDERR through a forked process that hands the line number back to you. Blech.) I've wanted it myself for the purpose of translating the error line number in an eval to the line number of the enclosing script. Ordinary magic variables won't cut it--the magic happens when the value is taken, and a magic $__LINE__ would give you the current line number in the subroutine, not the line number in the subroutine call. Do you really always want to have to force evaluation? &my_die($__LINE__ + 0); Hmm, I can just kludge it in the tokener to translate it to the literal line number. Then it would even be eligible for constant folding. Likewise for $__FILE__. Or maybe it should just be __LINE__, without the $. I think so, since it's not a variable. Or should I make the tokens "line" and "file" and blow everyone's loop labels? :-) Oh, now that I think of it, I guess you could always use -P and get the C preprocessor to translate __LINE__ and __FILE__ for you. But I'll add __LINE__ and __FILE__ to the Perl tokener. In fact, $__LINE__ wouldn't have worked if you DID use -P, so it won't have the $. Larry