...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

In reply to Re: Creating log files for errors and warnings by stevieb
in thread Creating log files for errors and warnings by tej

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.