On 12/2/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote about a
foreach loop with an empty list parameter:

> Now that seems just wrong ...  Not that it won't loop but that it
> doesn't warn or something.

There are thousands of places where Larry and the other Perl
developers have had to decide, Is this something to issue a warning
about?

Each programming language has its own rules about whether or not to
emit warnings, but the most common rule in Perl is, if you don't have
to have the warning, you shouldn't have the warning. In this case,
because it is easy for a programmer to write a test and warning if
needed, and because the behavior may be exactly what the programmer
intended, no warning is desirable.

If you ask for fewer than one of pretty much anything in Perl, you get
none at all, and no warning about it. That generally makes algorithms
simpler in Perl than they would be in a language which emits many
warnings. Few things annoy programmers more than having to code around
a nuisance warning about a non-bug.

>   #!/usr/local/bin/perl -w
>   use strict;
>   use warnings;
>   my @ar = ();
>
>   for(@ar){
>      print "$_\n";
>   }
>
> But running that script just does nothing but gleefully print a
> newline.

Under what version of perl? Maybe you have to compile your perl binary
with the -DGLEEFUL option to get the behavior you report; my perl
binary sullenly outputs nothing. But I wouldn't have it any other way.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to