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


in reply to Did I get what I expected (an array)?

Well, in your example, print $test == scalar(@test)?, you are not testing for what you probably think you are. :-)

When you return @x into scalar context, you get the number of elements in @x. (Aside: to return the "right thing" in whatever context the user called, use wantarray) So, your test will always work, because you are doing the same thing twice.

If you don't want a reference, test against ref. If you want to prove you only returned one value (or you returned > 1), assign to an array and test with scalar, as you are.

Perhaps you should ask, "Why do I care if I have a list/array vs a scalar value?" There is no difference between your example (returning one value) and return 'test' (also one value) (except, of course, your array will not return 'test' into scalar context...).

Does it really matter, as long as you get one or more correct values?

Russ
Brainbench 'Most Valuable Professional' for Perl

  • Comment on (Russ) Re: Did I get what I expected (an array)?