Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Executing line number

by ELISHEVA (Prior)
on Sep 09, 2009 at 14:33 UTC ( [id://794369]=note: print w/replies, xml ) Need Help??


in reply to Executing line number

One possibility:

print STDERR 'file: ' . __FILE__ . ', line: ' . __LINE__ . "\n";

In case you are wondering about all the concatenation, you can't use __FILE__ and __LINE__ inside double quotes. __FILE__ and __LINE are "special literals" and they lose their specialness inside double quotes. To learn more about __FILE__ and __LINE, look at perldata and search for the phrase "Special Literals".

Best, beth

Replies are listed 'Best First'.
Re^2: Executing line number
by Burak (Chaplain) on Sep 09, 2009 at 22:36 UTC
    I think printf() is more clear in such a situation :)
    printf STDERR "file: %s, line: %s\n", __FILE__, __LINE__;
Re^2: Executing line number
by johngg (Canon) on Sep 09, 2009 at 22:32 UTC

    You can use the babycart operator to interpolate bits of code into a double-quoted string, not that it saves much, if any, typing or looks any clearer.

    warn "file: @{ [ __FILE__ ] } line: @{ [ __LINE__ ] } - oops\n";

    I hope this is of interest.

    Cheers,

    JohnGG

      I think that anyone using this idiom must be punished :p

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-26 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found