Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Creating log files for errors and warnings

by stevieb (Canon)
on Aug 27, 2010 at 07:50 UTC ( [id://857627]=note: print w/replies, xml ) Need Help??


in reply to Creating log files for errors and warnings

...or, with a bit more complexity for `error checking'. Bit of a smartass, but it does copy/paste, and it does provide an example of named-ref style params :)

#!/usr/bin/perl use warnings; use strict; my $need_work = 10; my $i_tried = 0; my $die_if_its_broke = 0; # bool: true is fatal while ( $need_work > $i_tried ) { $i_tried++; handle_error({ value => $i_tried, die_if_broke => $die_if_its_broke, }); print "From main(), I've tried $i_tried\n"; } sub handle_error { my $params = shift; my $value_to_check = $params->{ value }; my $death = $params->{ die_if_broke }; my $error_condition = 5; if ( $value_to_check == $error_condition ) { die "Fatality!!: $!" if $death; open my $fh, ">", 'logfile.txt' or die "Can't open the fscking file: $!"; my $error_statement = "We've hit the error threshold " . ": $error_condition!\n"; print $fh $error_statement; } }
Steve

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://857627]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-04-19 12:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found