Mailing List Archive

Re: perl or sybperl problem??
> From: Shigeya Suzuki <shigeya@foretune.co.jp>
>
> Hi,
>
> I found following problem when I try to copy the reference of the
> result hash value (which I got from Sybase query).
>
> The subroutine "DBGetTableInfo2" work fine, but "DBGetTableInfo" not.
> Only difference is following:
>
> If I create anonymous hash and copy it, it work fine:
> But this if I grab a reference it is not:
>
> $cols{$data{name}} = \%data;
>
> Is this known behavior? Am I misunderstanding something?
>
The latter. Use

$cols{$data{name}} = { %data };

otherwise every %cols entry points at the _same_ instance of %data.

> shigeya
>
Tim.
Re: perl or sybperl problem?? [ In reply to ]
Thank you very much for quick follow-up..

>>>>> "Tim" == Tim Bunce <Tim.Bunce@ig.co.uk> writes:

Tim> The latter. Use
Tim> $cols{$data{name}} = { %data };

This work fine.

Tim> otherwise every %cols entry points at the _same_ instance of %data.

Now more question..

If it's point at _same_ instance of %data, the script at least show a
last fetched data. But if I ran the program, it show:

------------------------------
db0 197% ./test2.pl
test 1...
au_id:
au_ord:
royaltyper:
title_id:
test 2...
au_id:
scale =>
usertype => 101
name => au_id
prec =>
au_ord:
scale =>
usertype => 5
name => au_ord
prec =>
royaltyper:
scale =>
usertype => 7
name => royaltyper
prec =>
title_id:
scale =>
usertype => 102
name => title_id
prec =>
------------------------------

Any idea?

shigeya
Re: perl or sybperl problem?? [ In reply to ]