On 12/23/05, Juerd <[EMAIL PROTECTED]> wrote: > Luke Palmer skribis 2005-12-23 16:16 (+0000): > > However, I think that would be ignoring the amazing prevelance of the > > shallow copy idioms in perl 5: > > [ @array ] > > { %hash } > > It's a great idiom. Not much typing, easy on the eyes and easy to > understand. > > There's little, if any, reason to use a .clone method instead.
Uh, I was talking about shallow copy of arbitrary objects, not just of arrays and hashes. > > We could consider .clone to be the natural extension of this (and have > > the above forms be its definition for Array and Hash). > > I think both shallow and deep should be possible, with an infinite > amount of options in between. One hashref may be meant as a nested hash, > while the other is meant as a reference to a conceptually separate hash. > The first should be copied, the second not. How on earth we're going to > let Perl know what we want is, in my opinion, much more interesting than > what the default behaviour will be. > > Consider > > my %foo = ( > a => 41, > b => 15, > c => { > bar => 1, > baz => 1, > quux => 0, > }, > d => \%bar, > ); > > I'd want something that clones this, somewhere between shallow and deep. > .<c> should be deep, but .<d> shallow. Perhaps this can be determined > using some attribute, that for a referenced hash defaults to the > opposite of what it defaults to for a literal anonymous hash. That's an interesting idea. A "deep reference". I imaging you're suggesting this because you had a situation in real life where it came up. Can you describe that? Luke