I'm not sure I understand your question. The most common way to print a message and exit is with die:

$date1 =~ /(\d\d)(\d\d)(\d\d)/ or die "Invalid date format"; $time1 =~ /(\d\d):(\d\d)/ or die "Invalid time format";

Or are you talking about catching the error from gmtime? You're doing that properly, and I don't believe there's a better way to do it. When I have code like this, I will often wrap the entire thing in an eval, like this:

eval { my $ref = shift; my $date1 = shift @$ref; my $time1 = shift @$ref; die unless $date1 =~ /(\d\d)(\d\d)(\d\d)/; my @date2 = ($1,$2,$3); die unless $time1 =~ /(\d\d):(\d\d)/; my @time2 = ($1,$2); my $t; $t = timegm(0,$time2[1],$time2[0],$date2[1],$date2[0]-1,$dat +e2[2]+100)}; }; print "-1\n" and exit if $@;
It consolidates the error handling better.

In reply to Re: Comedy of StdErrs by sgifford
in thread Comedy of StdErrs by abitkin

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.