Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Well, I would say you have these options to trap the error:
  1. eval it and check for errors in $@
  2. use an if/else statement as above.
  3. use a little open B,"$blah" or error_subroutine("$!")#and do stuff in the routine.
The thing is, if you do not open the file successfully and do not write/read the data you want from/to the file correctly, it could (and most likely will) cause some problems down the road.

If you are using -w or warnings as you should, you might get those annoying little Use of uninitialized value errors which could keep your program from working at all.

The advice I would give you is, just die if something goes wrong because your program just might die later (unless you clog your program with double-checks everything). So, I would use this:
unless(open FH,"$file"){ open(LOG,">>$log") or die"Error writing to error-log file...how we +ird: $!"; print "Error at ",__LINE__," here's what happened: $!"; close LOG; }else{ proceed as normal.... }
UPDATE: Thank you to crazyinsomniac for pointing out that open FH, $file || or die; will always result as true and hence never fail. Three cheers for my hero! ;)


$_.=($=+(6<<1));print(chr(my$a=$_));$^H=$_+$_;$_=$^H; print chr($_-39); # Easy but its ok.

In reply to Re: q. on style/technique by damian1301
in thread Question on style/technique by synapse0

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, 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, 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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (9)
    As of 2021-01-28 16:11 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?