in reply to qw with anonomous list ref
None is better, because they do different things! qw// is basically a compile-time construct that (as Deparse shows) returns a LIST. \ LIST is a special form of reference-list constrctor and returns a LIST where each element is a reference to the element of the original list:
my @x = \qw(a b c); print "$_ $$_ \n" for @x;
[] creates an anonymous ARRAY-ref, which turns out to be a scalar value in the end:
my @x = [qw(a b c)]; #@x has one element print "$_ @$_\n" for @x;
So when you evaluate \LIST in scalar context, you get what you alway get when forcing a list to scalar context: the last element:
my $x = \qw(a b c); print "$x $$x\n";
HTH
--
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: qw with anonomous list ref
by John M. Dlugosz (Monsignor) on Oct 29, 2002 at 15:14 UTC | |
|
Re: Re: qw with anonomous list ref
by Jenda (Abbot) on Oct 29, 2002 at 21:15 UTC | |
by BrowserUk (Patriarch) on Oct 29, 2002 at 21:57 UTC | |
by Aristotle (Chancellor) on Oct 29, 2002 at 22:58 UTC | |
by blssu (Pilgrim) on Oct 30, 2002 at 12:59 UTC |