http://qs321.pair.com?node_id=525156


in reply to Re: the basic datatypes, three
in thread the basic datatypes, three

Why do we need to key scalar(@list) when only @list would also work?
for e.g.
use strict; my @abc= ('a','b','c','d'); my $x= @abc; my $y = scalar(@abc); print $x."#".$y;
Here $x & $y both return 4.

Replies are listed 'Best First'.
Re^3: the basic datatypes, three
by merlyn (Sage) on Jan 24, 2006 at 14:10 UTC
    The "scalar" op is needed only to provide scalar context in an otherwise list context space. For example:
    my @lengths = scalar @x, scalar @y, scalar @z; # but... my $length_x = @x; my $length_y = @y; my $length_z = @z;
    The scalar is needed in the first example because the array names are in a list context otherwise.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

A reply falls below the community's threshold of quality. You may see it by logging in.