Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Line 4 is still a lot of fanning-about, but it doesn't even compile

"@{[__LINE__}]" is a syntax error because you've swapped the } and ] - "@{[__LINE__]}" works fine.

some convenient token such as $LINE (or $__LINE__ or whatever I can just embed in double-quotes)

Nope, at least not built in, sorry. __LINE__ is like a function call, as of Perl 5.16 you can even write it as __LINE__().

Personally, I'd suggest living with the "fanning-about" or writing a helper function to output debug info (e.g. using caller). (Update: TIMTOWTDI - AnomalousMonk's printf suggestion is nice too. Personally, if it was a case where I didn't feel like it's worth it to write a helper, I'd probably write print "Line ",__LINE__,"\n";)

But since this is Perl, of course there's also a way to hack it:

use warnings; use strict; { package LineNumber; sub TIESCALAR { bless {}, shift } sub FETCH { (caller)[2] } } tie my $LINE, 'LineNumber'; print "Line $LINE\n"; print "Line $LINE\n";

In reply to Re: Is there a better way to use the line number in a quoted string than __LINE__? by haukex
in thread Is there a better way to use the line number in a quoted string than __LINE__? by davidfilmer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-24 00:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found