http://qs321.pair.com?node_id=184771


in reply to Can I clean this up??

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"));