Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 4 Apr 2010 14:48:14 -0400
From:      Alejandro Imass <ait@p2ee.org>
To:        Polytropon <freebsd@edvax.de>
Cc:        Chad Perrin <perrin@apotheon.com>, FreeBSD Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: perl qstn...
Message-ID:  <o2oa14066a01004041148zd4ef8167q32b04d58daec8f9f@mail.gmail.com>
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> <j2ya14066a01004040945z39191770k2f025752317fb14a@mail.gmail.com> <20100404163353.GA15198@guilt.hydra> <20100404201442.b456044e.freebsd@edvax.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Apr 4, 2010 at 2:14 PM, Polytropon <freebsd@edvax.de> wrote:
> On Sun, 4 Apr 2010 10:33:53 -0600, Chad Perrin <perrin@apotheon.com> 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 :-) ...
>

<grin>

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



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