Yes, you explained what you want. It's also clear you lack
some fundamental knowledge about Perl. You need to make yourself
more familiar with the concept
context.
A subroutine will return a list
if and only if it
was called in list context. A subroutine will return a
scalar
if and only if it was called in scalar context.
A subroutine will return nothing
if and only if it
was called in void context.
The crucial point is that it is the context that determines
whether the subroutine returns a list or a scalar - not the
subroutine.
Furthermore, parenthesis do not create lists (except in some
very specific syntax constructs). Parenthesis are used for
grouping.
return $this;
return ($this);
return (($this));
return ((($this)));
all mean the same. The do not differ just like there is no
difference between:
3 + 4;
(3 + 4);
(3) + (4);
((3) + (4));
As for
return @x;
that will return the number of elements of
@x
in scalar context, and a list consisting of the elements
of
@x in list context. Perl will never return
an array. You can check for yourself:
my @x = qw /foo bar baz/;
sub my_func {return @x};
(my_func) [1] .= "hello";
This gives a compile error:
Can't modify list slice in concatenation (.) or string
Note that it says "list slice". A list, not an array.
Abigail
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.