Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: array pre-allocation trick

by sauoq (Abbot)
on Oct 31, 2002 at 02:43 UTC ( [id://209316]=note: print w/replies, xml ) Need Help??


in reply to Re: array pre-allocation trick
in thread array pre-allocation trick

Are you sure that trick with array pre-allocating does what you think it does? My short experiment suggests otherwise:

$ perl -le '$#{\my @array}=100;print scalar @array' 0 $ perl -le 'my @array;$#array=100;print scalar @array' 101

Using strict clears things up...

$ perl -le 'use strict;$#{\my @array}=100;print scalar @array' Global symbol "@array" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.

The my lexically scopes @array to the block which you then use as a reference.

-sauoq
"My two cents aren't worth a dime.";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-18 06:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found