Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Anon. array of refs to a range generated list of scalars.

by Arien (Pilgrim)
on Jan 19, 2003 at 14:47 UTC ( [id://228165]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://228165]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2025-01-21 20:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (61 votes). Check out past polls.