Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

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

To explain tye's whimsical (musical?) solution, a bit...

If you pass die a string exception that ends in anything other than a newline, Perl will helpfully insert its own message complete with file and line number. If you give it a "\n" like Eliya did, it won't add "Died at file, line", but you will still get the new line.

On the other hand, if you give die an object, Perl will try to stringify the object. Normally, that would result in something noisy like Fart=ARRAY(0x871ff0). However, if you use overload, you can provide your own rule for stringify-ing an object. In tye's example, he stringified it to an empty string, hence silence instead of farts.

My own much less humorous version, gets rid of the extra array creation and encapsulates the blessing and act of dying. It's not as funny, but maybe a bit more practical:

{ package DieSilently; use overload q{""} => sub { '' }; sub now { die bless(\$_[0],$_[0]) } } print STDERR "Hello!\n"; DieSilently->now(); print STDERR "World!\n"; #outputs ($ are the command prompt) $ Hello! $

In reply to Re^2: Die silently? (/^but+$/) by ELISHEVA
in thread Die silently? by Anonymous Monk

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 goofing around in the Monastery: (5)
As of 2024-04-25 08:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found