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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.