Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 meditating upon the Monastery: (4)
As of 2015-07-05 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls