Archive of UserLand's first discussion group, started October 5, 1998.

Re: How to push Perl hash through XML RPC?

Author:Kragen Sitaker
Posted:1/20/1999; 7:49:28 AM
Topic:Frontier on MacOS X Server
Msg #:2300 (In response to 2259)
Prev/Next:2299 / 2301

It's technically true that your hash keys must be strings, but you can evaluate any scalar in a string context and get a string out of it. For example, this Perl code:

my $x = {'a' => 'b'};

my $y = {$x => 'asdf'};

print keys %$y;

$y{$x} = 'asdfw';

print keys %$y;

will compile and run. But the output will be

HASH(0x22850)HASH(0x22850)

So you could use hash refs as hash keys if you wanted to, but it's not likely you'll have a use for this. (Two hashes with the same contents will, of course, have different addresses, and the same hash will continue to have the same address as its contents change.)

Technically, you can't really have a hash as a value in a hash, either, but you can have a *reference* to a hash there. (You can't even have a reference to a hash as a hash key -- just its string representation. If you extract that hash key later with 'keys', you can't dereference it.) And you can have a reference to an array, or a scalar, or any of the other various arcane data types Perl has.




This page was archived on 6/13/2001; 4:47:26 PM.

© Copyright 1998-2001 UserLand Software, Inc.