I have some trouble indexing hashtables.
I have the following code snippet:
.sub main
.local pmc x
x = new .Hash
.local pmc y
y = new .Hash
x["y"] = y
$P10 = new .Integer
$P10 = 1
x["y;a"] = $P10 # (1) this does not work with the code below
y["a"] = $P10 # (2) this does work with the code below
# accessing x.y.a in 2 steps
$P99 = x["y"]
$P98 = $P99["a"]
printerr $P98
end
.end
x.y.a = 1;
print(x.y.a);
x and y are both hashtables.
x has a field "y", storing y
y has a field "a", storing an integer
I'd like to get the field "a" step by step, so first get a reference to
x.y, then get a reference to y.a, instead of indexing at once with "y;a"
as done at (2). Doing it step by step makes generating code a bit
easier, in my opinion.
I'm wondering what I'm doing wrong, because it looks like it should be
working (right?)
regards,
klaas-jan
> I have some trouble indexing hashtables.
>
> I have the following code snippet:
>
> x["y;a"] = $P10 # (1) this does not work with the code below
> y["a"] = $P10 # (2) this does work with the code below
>
>
> x.y.a = 1;
> print(x.y.a);
>
> x and y are both hashtables.
> x has a field "y", storing y
> y has a field "a", storing an integer
>
> I'd like to get the field "a" step by step, so first get a reference
> to x.y, then get a reference to y.a, instead of indexing at once with
> "y;a" as done at (2). Doing it step by step makes generating code a
> bit easier, in my opinion.
>
> I'm wondering what I'm doing wrong, because it looks like it should be
> working (right?)
I'm just guessing here, but doesn't #1 above add 1 to x with key "y;a"?
For example, if your intention in Perl 5 was '$x->{y}{a} = 1', doesn't
#1 mean '$x->{"y;a"} = 1'?
Josh
> x["y;a"] = $P10 # (1) this does not work with the code below
You want:
x["y"; "a"] = $P10
leo