Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
The stupid question is the question not asked
 
PerlMonks  

Re: pointers == arrayrefs ?

by snoopy (Deacon)
on Jan 09, 2008 at 06:56 UTC ( #661272=note: print w/ replies, xml ) Need Help??


in reply to pointers == arrayrefs ?

Some experimentation:

#!/usr/bin/perl use warnings; use strict; my %seen; for (0...1000) { my $a = [0..sprintf("%d", 1 + rand(20))]; die "$_ iteratations: I've already seen $a" if exists $seen{$a}; $seen{$a} = 1; }
This dies unpredictably (varying number of iterations and at different addresses), eg:
8 iteratations: I've already seen ARRAY(0x180bc0c) at at1.pl line 9.
However, if I change the last line to
$seen{$a} = $a; # capture the reference
..then my program does run to completion.

Addresses are unique when arrays are current. But they may become invalid and/be reused when arrays go out of scope.


Comment on Re: pointers == arrayrefs ?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2014-04-19 00:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (473 votes), past polls