|
#1
|
|||
|
|||
|
Hello
i have set up an alias system for a DB like reference system. This means that i have a set of records that might be manipulated and a delegation function that returns a given data record by key. Now in certain cases, mainly displaying, it is interesting to know if the given record is an alias or a plain record, In the database i hold for aliases a reference on a hash, which represents the datarecord. the delegator that returns the hash ny bame makes the test if its an alias, in which case till now it returned the record, otherwise returns directly the record. Now i wanted to change this and create a new record, means a new hash, with inside references onto the original record (that way that when manipulating this record the original dataset is changed) and an additional key indicating that this record is in fact an alias. most fields in the dataset-hash are themselves references, so passing them to the new hash doesn't make any problems, problems arise for the fields that are in fact scalars.... and i have no idea on how to specify to pass the scalar inside of a hash by reference and not by value... this: $tmpRes->{$entry} = \{$tmpRet->{$entry}}; doesn't work.... any help welcome -- ciao bboett ================================================== ============ [email]bboett@adlp.org[/email] [url]http://inforezo.u-strasbg.fr/~bboett[/url] |
|
#2
|
|||
|
|||
|
Bruno Boettcher wrote:
> and i have no idea on how to specify to pass the scalar inside of a hash > by reference and not by value... > > this: > $tmpRes->{$entry} = \{$tmpRet->{$entry}}; > doesn't work.... I'm not sure that I follow you, but does $tmpRes->{$entry} = \$tmpRet->{$entry}; or $tmpRes->{$entry} = \($tmpRet->{$entry}); work for you? |
|
#3
|
|||
|
|||
|
[email]bboett@bboett.dyndns.org[/email] (Bruno Boettcher) writes:
> > most fields in the dataset-hash are themselves references, so passing > them to the new hash doesn't make any problems, problems arise for the > fields that are in fact scalars.... I'd need to see more of your code to understand exactly what you're doing and why it doesn't work. But here's an idea, why not store scalars as references-to-scalars instead, so then everything stored in your hash is a reference, and therefore will work ok. #!/usr/bin/perl use strict; use warnings; my %hash = (); my %hash2 = (); my $scalar = "hello"; $hash{xxx} = \$scalar; $hash2{zzz} = $hash{xxx}; ${$hash2{zzz}} = "goodbye"; print("hash{xxx} = ", ${$hash{xxx}}, "\n"); print("hash2{zzz} = ", ${$hash2{zzz}}, "\n"); print("scalar = $scalar\n"); __END__ -- Tabs are 8 characters. They are NOT adjustable. Never have been, never will be. Anybody who thinks tabs are anything but 8 chars apart is just wrong. It's that simple. -- Linus Torvalds [url]http://beable.com/[/url] |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|