in reply to Anon. array of refs to a range generated list of scalars.

Says the manual about the range operator:
In list context, it returns an list of values counting (up by ones) from the left value to the right value. If the left value is greater than the right value then it returns the empty array.

What is that "n" doing there? It seems "list" was once "array"... (update: the documentation for Perl 5.6 indeed says "array", I am quoting from the docs for 5.8) And shouldn't that last part be "the empty list"?

A couple of sentences later, it says:

In the current implementation, no temporary array is created when the range operator is used as the expression in foreach loops, but older versions of Perl might burn a lot of memory when you write something like this:
for (1 .. 1_000_000) { # code }

This seems to suggest that when not used in for (foreach) a temporary array is created, which would explain a lot...

— Arien

Replies are listed 'Best First'.
Re: Re: Anon. array of refs to a range generated list of scalars.
by jdporter (Paladin) on Jan 21, 2003 at 17:01 UTC
    This seems to suggest that when not used in for (foreach) a temporary array is created...
    It's not clear. Certainly an array seems to be created in the case of \(5..9), because a reference to the array is returned. (This in itself is very odd.)

    But in the case of @a = (5..9), there's no way to tell (without guts diving).
    And the range operator is overloaded to have completely different semantics in scalar context,
    so we can't even do the simple $n=(5..7); if ( $n == 3 ) test for an array.

    jdporter
    The 6th Rule of Perl Club is -- There is no Rule #6.