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

comment on

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

longmess and shortmess do include caller information. The key is how deep you are in the stack, as Carp has a set of rules for deciding how much stack trace (if any) to include. I'm not 100% sure the rules are consistent across all the calls. Here's a test program that illustrates. Maybe a monk with more Carp knowledge can comment. I need to think about it some more ... I suspect there's some nonobvious consistency here.

use strict; use Carp qw(cluck); sub test_errors { cluck "First test message"; my $long = Carp::longmess("Second test message"); my $short = Carp::longmess("Third test message"); print STDERR $long; print STDERR $short; test2(); } sub test2 { cluck "Fourth test message"; my $long = Carp::longmess("Fifth test message"); my $short = Carp::longmess("Sixth test message"); print STDERR $long; print STDERR $short; } test_errors();
produces:
First test message at cluckt line 8 main::test_errors() called at cluckt line 30 Second test message at cluckt line 30 Third test message at cluckt line 30 Fourth test message at cluckt line 21 main::test2() called at cluckt line 16 main::test_errors() called at cluckt line 30 Fifth test message at cluckt line 16 main::test_errors() called at cluckt line 30 Sixth test message at cluckt line 16 main::test_errors() called at cluckt line 30

Basically, longmess and shortmess appear to always include one less stack frame than cluck does. Maybe someone should cluck about this. ;-)

Note that I got the same results by calling longmess and shortmess directly in the print calls rather than getting the messages into local variables first.


In reply to Re: But cluck gives you more. by steves
in thread How do I get Cluck output into a log file? by tphyahoo

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 pondering the Monastery: (5)
As of 2024-03-28 21:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found