develooper Front page | perl.perl5.porters | Postings from April 2003

Re: [perl #22027] undef appears as scalar return value for a list

Thread Previous | Thread Next
From:
Mark Jason Dominus
Date:
April 24, 2003 19:48
Subject:
Re: [perl #22027] undef appears as scalar return value for a list
Message ID:
20030425024836.10158.qmail@plover.com
Rick Delaney <rick.delaney@rogers.com>:
> On Thu, Apr 24, 2003 at 01:40:54PM -0400, Mark Jason Dominus wrote:
> > mike@stok.co.uk:
> > > > > my $rv = ('a', 'b', 'c');
> > > > > show $rv;
> > > > > my $rv2 = ('a', 'b', 'c', ());
> > > > > show $rv2;
> > > > > 
> > > > > I would have expected $rv2 to be 'c' as I thought ('a', 'b',
> > > > > 'c', ()) should be flattened to ('a', 'b', 'c').  The warnings
> > > > > indicate that in the first case two values are useless, and in
> > > > > the second three values are useless.
> > 
> > I'm with Mike on this.  
> > 
> >         my $rv2 = ('a', 'b', 'c', ());
> >         my $rv2 = ('a', 'b', 'c', );
> > 
> > These two should not be different.
> 
> Should these be different?
> 
>     my $rv2 = ('a', 'b', 'c', f());
>     my $rv2 = ('a', 'b', 'c', );
>     sub f { () }

Yes.

This

     my $rv2 = ('a', 'b', 'c', f());
     sub f { () }

is identical to this:

     my $rv2 = ('a', 'b', 'c', f());
     sub f { }

because the empty parentheses don't matter.

Analogously, this

     my $rv2 = ('a', 'b', 'c', ());

should be identical to this:

     my $rv2 = ('a', 'b', 'c', );

because the empty parentheses don't matter.



> If so, why should the inline expression behave differently from the
> function call?


Because a function call returns a value.


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About