Front page | perl.perl5.porters |
Postings from September 2002
Re: Collections
Thread Previous
|
Thread Next
From:
'Brian Ingerson'
Date:
September 29, 2002 13:11
Subject:
Re: Collections
Message ID:
20020929131057.A746@ttul.org
On 29/09/02 12:33 -0700, Brent Dax wrote:
> Brian Ingerson:
> # We have to consider the following issues:
> # - mutability of SVs
> # - indentity vs equality
> # - hashing algorithm for deep structures
>
> For the first problem, at least, if we had COW on SVs it wouldn't be a
> problem.
I may have used vague terminology here. When I said SV I meant perl
structures in general, like HV-s and AV-s.
'use keys' wouldn't affect regular SV-s unless they were referenced:
use keys;
my (%hash, $key);
$key = "foo";
$hash{$key} = "bar";
# hashed on the string value of $key. like normal.
$hash{\$key} = "baz";
# the SV of $key now gets some special magic. It is hashed according
# to the keys->HASH() method.
$key = "buzz";
$hash{\$key} eq "baz" or die;
# HASH() value is cached.
keys::rehash(\$key);
# not sure how this affects CORE::keys($hash)
$hash{\$key} = "balloon";
$hash{"foo"} eq "bar" or die;
$hash{\"foo"} eq "baz" or die;
$hash{\"buzz"} eq "balloon" or die;
# The SV for the "foo" constant gets some magic.
# $value eq 'baz' because the HASH method preserves equality
In YAML:
foo: bar
? !perl/ref foo
: baz
? !perl/ref buzz
: balloon
Cheers, Brian
Thread Previous
|
Thread Next