Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 4 Apr 2010 20:14:42 +0200
From:      Polytropon <freebsd@edvax.de>
To:        Chad Perrin <perrin@apotheon.com>
Cc:        FreeBSD Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: perl qstn...
Message-ID:  <20100404201442.b456044e.freebsd@edvax.de>
In-Reply-To: <20100404163353.GA15198@guilt.hydra>
References:  <20100403210610.GA4135@thought.org> <4BB8108A.9080104@FreeBSD.org> <1270371713.5861.98.camel@tao.thought.org> <86aatjnsts.fsf@red.stonehenge.com> <861vevnsow.fsf@red.stonehenge.com> <j2ya14066a01004040945z39191770k2f025752317fb14a@mail.gmail.com> <20100404163353.GA15198@guilt.hydra>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 4 Apr 2010 10:33:53 -0600, Chad Perrin <perrin@apotheon.com> 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";
		exit;
	}

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: blabla.pl <filename>\n";

or

	print "Use: blabla.pl <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
successfully).

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. :-)
	
-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100404201442.b456044e.freebsd>