Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: q. on style/technique

by damian1301 (Curate)
on Jul 06, 2001 at 04:56 UTC ( #94355=note: print w/replies, xml ) Need Help??


in reply to Question on style/technique

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://94355]
help
Chatterbox?
[atcroft]: james28909: That particular questions was a bit of trick, actually (depending on the country you are in). More interesting is, if you are trying to subtract from an epoch time, for instance, you might have to consider when/if DST occurs for a location,
[atcroft]: because you may have to adjust the number of seconds you change from an epoch from 86400 (not to mention leap seconds)....
[atcroft]: james28909: Although if your program is using a database, you might be able to "pass the buck" to the database and ask it to do the date change for you....
[stevieb]: ++ atcroft

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2017-04-29 04:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (531 votes). Check out past polls.