Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

The problem here is that your "\n" line ending within your eval string are being interpolated before the string is eval'd. Effectively, you are double spacing your lines of code. escaping the "\n"s, make the problem go away.

P:\test>perl print __LINE__, "\n"; print __LINE__, "\n"; eval "print __LINE__,qq/\\n/; print __LINE__,qq/\\n/; die()"; print $@, "\n"; print __LINE__, "\n"; ^Z 1 2 1 2 Died at (eval 1) line 3. 7

I've fairly recently started coding my (rare) uses of eval like this.

#! perl -slw use strict; print __LINE__; print __LINE__; eval <<"EOS"; # line 1 "@{[__PACKAGE__]} eval @ line @{[__LINE__]}" warn; warn; die(); EOS print $@; print __LINE__; __END__ P:\test>junk 4 5 Warning: something's wrong at main eval @ line 6 line 1. Warning: something's wrong at main eval @ line 6 line 2. Died at main eval @ line 6 line 3. 14

This allows you to get very useful error messages from within the evals, telling you not only which line number within the eval failed and why, but also the package name and line number at which the eval is located. Not so important when the eval is in main as here, though knowing which line number is useful if there are more than one in the file, but it really comes into it's own when the eval is located in a module.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!


In reply to Re: Re: Re: Line Numbers by BrowserUk
in thread Line Numbers by Sprad

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 having an uproarious good time at the Monastery: (5)
As of 2024-04-24 07:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found