Actually, a for loop does return something. Assuming it runs at least once, it will return an empty string, alias scalar false.
There seems to be no particular reason for that behaviour.
Makeshifts last the longest.
| [reply] [Watch: Dir/Any] |
$ perl -wle 'print "yes" if !1 == 0 '
yes
$ perl -wle 'print "yes" if "" == 0 '
Argument "" isn't numeric in numeric eq (==) at -e line 1.
yes
-sauoq
"My two cents aren't worth a dime.";
| [reply] [Watch: Dir/Any] [d/l] [select] |
The difference is more visible this way:
use Devel::Peek;
Dump("");
Dump(!1);
The output of which is
SV = PV(0x816d944) at 0x8163c48
REFCNT = 1
FLAGS = (PADBUSY,PADTMP,POK,READONLY,pPOK)
PV = 0x8167830 ""\0
CUR = 0
LEN = 1
SV = PVNV(0x814d6a0) at 0x814c600
REFCNT = 2147483647
FLAGS = (PADBUSY,PADTMP,NOK,POK,READONLY,pNOK,pPOK)
IV = 0
NV = 0
PV = 0x814d678 ""\0
CUR = 0
LEN = 1
| [reply] [Watch: Dir/Any] [d/l] |
Ah, interesting; I guess Perl DWIMs this so well I had never paid enough attention to notice the subtlety. Reminds me of the games some people played elsewhere on the Monastery quite a while ago with scalars that had specific, different values when evaluated as numbers or as strings (without overloading, if memory serves). (Alas, I cannot remember any useful keywords to Super Search it.)
Makeshifts last the longest.
| [reply] [Watch: Dir/Any] |
Oh, and another thing: you can use either 0 or 1 as a constant in void context without getting a warning, but you can also use any string that starts with "ig", "ds", or "di", as Dominus famously demonstrated.
Makeshifts last the longest.
| [reply] [Watch: Dir/Any] |
as well as as the last statement in a required file/module.
Well, you can use whatever you want as the last statement of a required module without getting the "Useless use of a constant in void context" warning.
-sauoq
"My two cents aren't worth a dime.";
| [reply] [Watch: Dir/Any] |
| [reply] [Watch: Dir/Any] [d/l] |