From owner-freebsd-questions@FreeBSD.ORG Sun Apr 4 18:48:15 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 D0E821065675 for ; Sun, 4 Apr 2010 18:48:15 +0000 (UTC) (envelope-from aimass@yabarana.com) Received: from mail-qy0-f195.google.com (mail-qy0-f195.google.com [209.85.221.195]) by mx1.freebsd.org (Postfix) with ESMTP id 934768FC18 for ; Sun, 4 Apr 2010 18:48:15 +0000 (UTC) Received: by qyk33 with SMTP id 33so3566089qyk.28 for ; Sun, 04 Apr 2010 11:48:14 -0700 (PDT) MIME-Version: 1.0 Sender: aimass@yabarana.com Received: by 10.229.218.137 with HTTP; Sun, 4 Apr 2010 11:48:14 -0700 (PDT) In-Reply-To: <20100404201442.b456044e.freebsd@edvax.de> 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> <20100404201442.b456044e.freebsd@edvax.de> Date: Sun, 4 Apr 2010 14:48:14 -0400 X-Google-Sender-Auth: 94c5324f93716165 Received: by 10.229.81.81 with SMTP id w17mr7655734qck.4.1270406894607; Sun, 04 Apr 2010 11:48:14 -0700 (PDT) Message-ID: From: Alejandro Imass To: Polytropon Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Chad Perrin , FreeBSD Mailing List Subject: Re: perl qstn... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Apr 2010 18:48:16 -0000 On Sun, Apr 4, 2010 at 2:14 PM, Polytropon wrote: > On Sun, 4 Apr 2010 10:33:53 -0600, Chad Perrin wrot= e: >> 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. > _precisely_ what unless is for. it's just a funny way of writing if(!... or should I say if(! is a funny way to write unless ;-) But honestly pun aside unless(){} is far more readable than if(!){} and _especially_ if you are programming in an exception manner as you correctly point out. Every language should have an unless construct. [...] > And you could even force perl to exit with an exit code !=3D 0 > to indicate that something happened (e. g. program wasn't run > successfully). > a good practice in any language... > 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. > ahh! the clarity of unless > > > > PS. I'm not familiar with perl enough to be sure that the ! > =A0 =A0operator can be used at @ARGV to make sure it's > 0, In "scalar context" will automagically return the number of elements perldoc perlintro (section Perl variable types) > =A0 =A0and how or if to use exit() to set the return code. die "Bailing cause you forgot the filename" unless @ARGV Yes, that _is_ actual code :) Will not only die with a pretty message on STDERR but will return the value of $! (errno) as exit value. (no need to make up exit codes) Good thing we are on a FBSD list, because I can't see the sense of programming in a non-nix environment ;-) > =A0 =A0I hardly can read perl at all, so the essence of my > =A0 =A0examples is of a rather generic nature. :-) Look mommi! Reading Perl is just like reading plain english! (or in Nigerian spam for that matter http://search.cpan.org/~jwalt/Acme-Lingua-NIGERIAN-1.0.0/NIGERIAN.pm) Cheers, Alejandro Imass > > -- > Polytropon > Magdeburg, Germany > Happy FreeBSD user since 4.0 > Andra moi ennepe, Mousa, ... > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.o= rg" >