Gary wrote: > I hope this is the right place to ask this question. > > So I've seen code like this > > for (1..10) { > print $_ > } > > > What's going on behind the scenes with that?
In modern versions of Perl that is equivalent to: for ( $_ = 1; $_ >= 10; ++$_ ) { print $_ } In older versions of Perl that would create the list in memory first before it iterated over it. > Is it creating an array? No. perldoc -q "What is the difference between a list and an array" > What if I want to use > > for (1..1000000) ? > > Also, What's the internal structure of Perl arrays? perldoc perl [ snip ] Internals and C Language Interface perlembed Perl ways to embed perl in your C or C++ application perldebguts Perl debugging guts and tips perlxstut Perl XS tutorial perlxs Perl XS application programming interface perlclib Internal replacements for standard C library functions perlguts Perl internal functions for those doing extensions perlcall Perl calling conventions from C perlapi Perl API listing (autogenerated) perlintern Perl internal functions (autogenerated) perliol C API for Perl's implementation of IO in Layers perlapio Perl internal IO abstraction interface perlhack Perl hackers guide Also have a look at all the B::* and Devel::* modules. > I can't find anything on that. > I'm curious about how much time it takes to do something like insert into the > middle ofan array. Is that O(1)? Yes. $ perl -le' my @array = 0 .. 20; print "@array"; splice @array, 10, 0, "X", "Y", "Z"; print "@array"; ' 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 0 1 2 3 4 5 6 7 8 9 X Y Z 10 11 12 13 14 15 16 17 18 19 20 John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/