On Mon, Jun 16, 2003 at 10:59:45AM -0700, John W. Krahn wrote:
> Jair Santos wrote:
> > Can anybody explain whats the use of the   = ( ) =  ?
> 
> But perl has a shortcut that allows you to assign a list to () which in
> scalar context returns the number of elements in the list without having
> to create an array.
> 
> # with explicit array
> my $count = my @array = readdir $dh;
> 
> # perl shortcut with no array
> my $count = () = readdir $dh;

And the important little bit of magic which makes this work, rather than
setting $count to 0 as might be expected:

  "List assignment in scalar context returns the number of elements
  produced by the expression on the right side of the assignment"

Which is pretty much what John said.

perldoc perldata for more details.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to