perl qstn...

Polytropon freebsd at
Sun Apr 4 18:14:46 UTC 2010

On Sun, 4 Apr 2010 10:33:53 -0600, Chad Perrin <perrin at> wrote:
> On Sun, Apr 04, 2010 at 12:45:30PM -0400, Alejandro Imass wrote:
> > did you mean unless? ;-)
> I find "if" to be clearer than "unless" when there's an "else", so
> instead of making that "if" into an "unless", I'd just swap the
> conditional actions.

A quite language-independent technical sidenote :-) ...

If your if() conditional is to test an exception, something
that you usually DON'T want to happen - i. e. missing command
line parameters - you can use the ! negation operator to
indicate this in the if() argument.

	if(!@ARGV) {
		print "No args\n";

In a short error message, you should indicate what you are
expecting, e. g. with a synopsis or a simple example (no
need for a 25 line help text here, e. g.

	print "Input file name is missing.\n";
	print "usage: <filename>\n";


	print "Use: <inputfile>\n";

And you could even force perl to exit with an exit code != 0
to indicate that something happened (e. g. program wasn't run

Now, as the "don't want case" has been considered, you can
easily continue with your program, no need to put it into
an else { } branch.

PS. I'm not familiar with perl enough to be sure that the !
    operator can be used at @ARGV to make sure it's > 0,
    and how or if to use exit() to set the return code.
    I hardly can read perl at all, so the essence of my
    examples is of a rather generic nature. :-)
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

More information about the freebsd-questions mailing list