in reply to Re: Re: Why is my data structure wrong?
in thread Why is my data structure wrong?

Yes, using the x operator with references employs the same reference each time. Why? Because that's the most efficient way of doing it, I'd gather, regardless of whether you're using references or not!

As proof, run these in the Perl debugger. (The first x is the 'display this data' instruction to the debugger.) You could also check the source code (pp.c) where the repeatcpy() C function or macro is employed.

x map \$_, ("japhy") x 5; x ([]) x 5;

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re^4: Why is my data structure wrong?
by grantm (Parson) on Jun 25, 2002 at 08:26 UTC

    Why? Because that's the most efficient way of doing it, I'd gather

    Rather than some clever efficiency thing, I'd have thought it was simply because {} returns a scalar value. ('A') x 10 would give you 10 copies of the string 'A'. Similarly ( {} ) x 10 gives you 10 copies of a reference to a particular anonymous hash.

Re4: Why is my data structure wrong?
by Hofmator (Curate) on Jun 25, 2002 at 08:58 UTC
    What's a safe reference, I thought all references in Perl are safe ;-))

    -- Hofmator