On Sun, Apr 4, 2010 at 2:14 PM, Polytropon <[email protected]> wrote:
> On Sun, 4 Apr 2010 10:33:53 -0600, Chad Perrin <[email protected]> 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 :-) ...
>
<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 != 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 !
> operator 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)
> and 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 ;-)
> I hardly can read perl at all, so the essence of my
> examples 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, ...
> _______________________________________________
> [email protected] mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "[email protected]"
>
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[email protected]"