From owner-freebsd-questions@FreeBSD.ORG Sun Apr 4 18:14:46 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2052D106568C for ; Sun, 4 Apr 2010 18:14:46 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) by mx1.freebsd.org (Postfix) with ESMTP id D29CA8FC0C for ; Sun, 4 Apr 2010 18:14:45 +0000 (UTC) Received: from r55.edvax.de (port-92-195-100-7.dynamic.qsc.de [92.195.100.7]) by mx02.qsc.de (Postfix) with ESMTP id 2713B1E222; Sun, 4 Apr 2010 20:14:43 +0200 (CEST) Received: from r55.edvax.de (localhost [127.0.0.1]) by r55.edvax.de (8.14.2/8.14.2) with SMTP id o34IEhwA003088; Sun, 4 Apr 2010 20:14:43 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Sun, 4 Apr 2010 20:14:42 +0200 From: Polytropon To: Chad Perrin 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> <20100404163353.GA15198@guilt.hydra> Organization: EDVAX X-Mailer: Sylpheed 2.4.7 (GTK+ 2.12.1; i386-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: FreeBSD Mailing List Subject: Re: perl qstn... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Apr 2010 18:14:46 -0000 On Sun, 4 Apr 2010 10:33:53 -0600, Chad Perrin 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 \n"; or print "Use: blabla.pl \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, ...