in reply to scalar doesn't work values returned by a function?
To put sort into a list context there is no clean way to do it, (sort(@a)) doesnt do it in this case. But a snip from the perlfunc man pages for scalar says:@a=('a', 'b', 'c'); $a = sort(@a); print $a; Use of uninitialized value at - line 3.
So this does work with -w (but it is a bit of extra work):There is no equivalent operator to force an expression to be interpolated in list context because it's in practice never needed. If you really wanted to do so, however, you could use the construction @{[ (some expression) ]}, but usually a simple (some expression) suffices.
@a=('a', 'b', 'c'); $a = @{[sort(@a)]}; print $a;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: scalar doesn't work values returned by a function?
by Russ (Deacon) on May 10, 2000 at 07:11 UTC | |
by perlmonkey (Hermit) on May 10, 2000 at 08:38 UTC | |
by Russ (Deacon) on May 11, 2000 at 08:27 UTC | |
by perlmonkey (Hermit) on May 11, 2000 at 09:12 UTC | |
by ZZamboni (Curate) on May 11, 2000 at 09:37 UTC | |
by perlmonkey (Hermit) on May 11, 2000 at 11:08 UTC |