It shows 6 because a comma-separated literal list, when interpreted as a
scalar, evaluates to the final value in the list, not the length of the
list.  If you evaluate "scalar(1,2,,4,,7)", it will equal 7.  That's the
comma operator at work-- even though it looks like a list (and both use
commas), it's really just a sequential set of expressions.

Cheers,
James


On Wed, May 8, 2013 at 5:14 PM, <fe...@crowfix.com> wrote:

> On Wed, May 08, 2013 at 02:04:37PM -0400, Derek Jones wrote:
> > Huh?
> >
> > That produces 6 - as it should. What version of Perl are you working
> with?
>
> > On May 8, 2013, at 1:58 PM, fe...@crowfix.com wrote:
> >
> > > scalar(1,2,,4,,6)
>
> You are right -- but this produces 4 first, as I had always thought it
> would, and then 6, as I don't quite understand.  I would never use
> that kind of expression, and I sorta maybe understand why it says 6,
> but only in hindsight.
>
>     #!/usr/bin/perl
>
>     my @ary = (1,2,,4,,6);
>     print "Step 1: ", scalar(@ary), "\n";
>     print "Step 2: ", scalar(1,2,,4,,6), "\n";
>
> --
>             ... _._. ._ ._. . _._. ._. ___ .__ ._. . .__. ._ .. ._.
>      Felix Finch: scarecrow repairman & rocket surgeon / fe...@crowfix.com
>   GPG = E987 4493 C860 246C 3B1E  6477 7838 76E9 182E 8151 ITAR license
> #4933
> I've found a solution to Fermat's Last Theorem but I see I've run out of
> room o
>

Reply via email to