Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
here's an XS question this time regarding read-only variables...
In one of my "classes" my blessed thingy happens to be an HV which hold information about a distinguished name (canonical format, abbreviated, surname, given, common name, etc...).
i.e: print $name->{Common};
I'd like to be able to make that hash read-only and tried it (using SvREADONLY_on(HV)) but you can still do this:
$name->{valueNotInHashInitially} = "Some Value";
You can do that even though Devel::Peek show the hash as having the READONLY flag. I did set all the entries (SVs) in the hash to READONLY and that worked.
ie: $name->{Common} = "New Value"; raises an error and dies.
Is there anything I can do so Perl also raise the same error when a user tries to create new entries in my ReadOnly hash?
Thanks,
Christian Cloutier
In one of my "classes" my blessed thingy happens to be an HV which hold information about a distinguished name (canonical format, abbreviated, surname, given, common name, etc...).
i.e: print $name->{Common};
I'd like to be able to make that hash read-only and tried it (using SvREADONLY_on(HV)) but you can still do this:
$name->{valueNotInHashInitially} = "Some Value";
You can do that even though Devel::Peek show the hash as having the READONLY flag. I did set all the entries (SVs) in the hash to READONLY and that worked.
ie: $name->{Common} = "New Value"; raises an error and dies.
Is there anything I can do so Perl also raise the same error when a user tries to create new entries in my ReadOnly hash?
Thanks,
Christian Cloutier
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: XS ReadOnly HVs
by PodMaster (Abbot) on Apr 02, 2003 at 07:06 UTC | |
Re: XS ReadOnly HVs
by robin (Chaplain) on Apr 03, 2003 at 10:37 UTC | |
by Anonymous Monk on Apr 03, 2003 at 18:29 UTC | |
by robin (Chaplain) on Apr 04, 2003 at 10:38 UTC | |
by Anonymous Monk on Apr 04, 2003 at 17:15 UTC |
Back to
Seekers of Perl Wisdom