Get length of returned array without storing? - Perl
This is a discussion on Get length of returned array without storing? - Perl ; xhoster@gmail.com wrote:
> Big and Blue <No_4@dsl.pipex.com> wrote:
>> boole wrote:
>>> I want to get the length of that array without storing the result in
>>> an array variable.
>> my $len = (func_call());
>
> No, that does ...
-
Re: Get length of returned array without storing?
xhoster@gmail.com wrote:
> Big and Blue <No_4@dsl.pipex.com> wrote:
>> boole wrote:
>>> I want to get the length of that array without storing the result in
>>> an array variable.
>> my $len = (func_call());
>
> No, that does the same thing as not using the extra parens. Maybe you
> mean this:
>
> my $len = () = func_call();
Thanks - that's the effect I was looking for (so Uri - a pointer in the
right direction, rather than a guess - although it was untested).
Of course, if the function itself checked its context and just return
the length in a scalar context then this all becomes irrelevant. I was
assuming it doesn't and won't.
--
Just because I've written it doesn't mean that
either you or I have to believe it.
-
Re: Get length of returned array without storing?
jl_post@hotmail.com <jl_p...@hotmail.com> wrote:
> > you can easily get the
> > length of a list in scalar context
On Nov 1, 4:49 pm, Tad McClellan <ta...@seesig.invalid> wrote:
> No you can't.
>
> A list cannot even exist in a scalar context.
This might be just a matter of semantics, but when I wrote:
> you can easily get the length of a list in scalar context
I didn't mean:
> you can easily get the length of [a list in scalar context]
but rather:
> you can easily get the [length of a list] in scalar context
or even:
> [when in scalar context (such as assigning to a scalar
> or using scalar()),] you can easily get the length
> of a list
I didn't mean to imply that the list itself was in scalar context,
but just the final operation was (which in the case of:
my $length = () = ('a', 'b', 'c'); # $length is 3
would be the left-most '=' operator).
I can see how the way I worded that might be a bit ambiguous, but I
do think my examples clarified what I meant (and more importantly,
answered the original poster's question).
-- Jean-Luc
-
Re: Get length of returned array without storing?
>>>>> "BaB" == Big and Blue <No_4@dsl.pipex.com> writes:
BaB> xhoster@gmail.com wrote:
>> Big and Blue <No_4@dsl.pipex.com> wrote:
>>> boole wrote:
>>>> I want to get the length of that array without storing the result in
>>>> an array variable.
>>> my $len = (func_call());
>> No, that does the same thing as not using the extra parens. Maybe you
>> mean this:
>> my $len = () = func_call();
BaB> Thanks - that's the effect I was looking for (so Uri - a pointer in
BaB> the right direction, rather than a guess - although it was untested).
i don't like the () = trick anyhow. also i never seem to want the length
of lists. i always want the data. maybe i think differently but temp
lists just to generate counts seems like a waste.
BaB> Of course, if the function itself checked its context and just
BaB> return the length in a scalar context then this all becomes
BaB> irrelevant. I was assuming it doesn't and won't.
that is also a poor assumption. you can check the context and return
many things besides the count in scalar context. i have modules that
would return an array ref of the data instead of a list/array
itself. some code may return some other info like a handle or object in
scalar context that may be used in chaining calls (a style i don't like
either). it is up to the module designer and not the users of the module
that determines what is returned.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
-
Re: Get length of returned array without storing?
On Nov 2, 1:39 am, Uri Guttman <u...@stemsystems.com> wrote:
> >>>>> "BaB" == Big and Blue <N...@dsl.pipex.com> writes:
> BaB> I was assuming it doesn't and won't.
> that is also a poor assumption.
Actually, I think it's more likely to be affected use of English.
I suspect BaB wrote "I was assuming it doesn't" when he meant "I
wasn't assuming it does".
This is rather an unfortunately common affectation in the general
population.
Similar Threads
-
By Application Development in forum Javascript
Replies: 3
Last Post: 09-23-2007, 02:16 PM
-
By Application Development in forum C
Replies: 23
Last Post: 08-28-2007, 06:54 PM
-
By Application Development in forum Idl-pvwave
Replies: 0
Last Post: 07-11-2007, 12:48 AM
-
By Application Development in forum ADO DAO RDO RDS
Replies: 0
Last Post: 01-21-2006, 09:44 AM
-
By Application Development in forum Perl
Replies: 1
Last Post: 08-14-2003, 01:50 PM