Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
It's a simple case of refactoring. I really dislike duplication, since duplication is just asking for bugs. As a note, it seems you're writing to FIL before you open it.
if ($ct > 0) { open(FIL, ">>$myfil") || die "Write to $myfil failed\n"; print FIL "\n$ct "; print FIL ($ct > 1)? "are not available" : "is down"; print FIL " at this time.\n"; close (FIL); system("mailx -s 'Mail Header' myemail < $myfil"); }
Note that you should probably be using something like Mail::Mailer or Mail::SendMail to do the dirty work of sending mail.

In your original code, if your e-mail address changed, you'd have to do twice the work to update it, and further, there is a chance you might miss one of them.

When handling simple pluralization, like what you have here, the ?: operator comes in handy. If you're not familiar with it, here's how it works:
print "\$foo is "; print $foo? "true" : "false"; print "\n";
Or you can compact this to something like so:
print "\$foo is ",($foo? "true" : "false"),"\n";
More idiomatically:
print "There ",(($num == 1)? "is" : "are")," $num camel", (($num == 1)? "" : "s")," for sale.\n";
Or perhaps something more "Old School":
printf("There %s $num camel%s for sale.\n", ($num == 1)? ("is","") : ("are","s"));

In reply to Re: Can I clean this up?? by tadman
in thread Can I clean this up?? by Anonymous Monk

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2023-03-28 02:17 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (66 votes). Check out past polls.