oyse has asked for the wisdom of the Perl Monks concerning the following question:
Hi
Is it possible in anyway to add a Perl attribute to a value instead of to a variable?
If I understand the docs correctly the following code associates an attribute with a variable given that the attribute MyAttr is available.
However I want to associate an attribute with a value and not with a variable. Something like this. Is this allowed in anyway?my $var :MyAttr;
my_func( 1, 'Hi there', { key => 'value } :MyAttr );
The above example could be solved by writing
my $var :MyAttr = { key => 'value' }; my_func( 1, 'Hi there', $var );
but that is not a satisfactory solutions in my case.
Also if an attribute cannot be associated with a value could anyone explain the reason behind this? I am wondering out of curiousity, it is not meant as a critisism to the attribute implementation in Perl.
Update: I no longer have use of actually doing this (see discussion below). I am however still curious if it is possible and if it is not, a possible explanation to why?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Adding attributes to values?
by GrandFather (Saint) on Oct 21, 2007 at 09:26 UTC | |
by oyse (Monk) on Oct 21, 2007 at 09:43 UTC | |
by rminner (Chaplain) on Oct 21, 2007 at 10:26 UTC | |
by oyse (Monk) on Oct 21, 2007 at 10:40 UTC | |
by rminner (Chaplain) on Oct 21, 2007 at 11:00 UTC | |
| |
by GrandFather (Saint) on Oct 22, 2007 at 00:06 UTC | |
by oyse (Monk) on Oct 22, 2007 at 12:05 UTC |