in reply to Re^7: index of the minimum element of the array
in thread index of the minimum element of the array
For reduce, no. It's not documented. It's a side-effect of the implementation you tested.
For map, yes. map is a not a subroutine; it's an operator. It's not constrained to the syntax and convention of subroutine calls Its argumentoperand is not a sub.
I also see coderef passed to the sub when run under debugger. But not when run normally.
It's easy to see by using return inside the block. It's also easy to see using -MO=Concise.
$ perl -MList::Util=reduce -MO=Concise,-exec -e'reduce { "..." } @a' ... 4 <0> pushmark sRM 5 <$> anoncode[CV ] lRM 6 <1> refgen KM/1 7 <#> gv[*a] s 8 <1> rv2av[t4] lKM/1 9 <#> gv[*reduce] s a <1> entersub[t5] vKS/TARG,1 ... {15} eric@dev-eric [~/work/p4/src/main/CC] $ perl -MList::Util=reduce -MO=Concise,-exec -e'&reduce(sub { "..." }, + @a)' ... 4 <0> pushmark sRM 5 <$> anoncode[CV ] lRM 6 <1> refgen lKM/1 7 <#> gv[*a] s 8 <1> rv2av[t4] lKM/1 9 <#> gv[*reduce] s a <1> entersub[t5] vKS/TARG,AMPER,1 ...
|
---|
In Section
Seekers of Perl Wisdom