Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

:lvalue, How I Hate Thee

by jk2addict (Chaplain)
on Aug 17, 2005 at 19:27 UTC ( #484548=perlquestion: print w/replies, xml ) Need Help??

jk2addict has asked for the wisdom of the Perl Monks concerning the following question:

I had reason to use the perl functionality built into a vendors software package today. The package comes with 5.8.3, and it's own set of perl modules to do software related tasks like tweaking data records.

At one point, I have to figure out why this didn't work:

$valobj->value = undef;

but this did:

$valobj->value = '';

After looking into the source code, the object and it's methods use the :lvalue attribute.

sub value : lvalue { my $this = shift; $this->{VALUE}; }

So, that doesn't work if lvalue is undef, but does work if lvalue is an empty string. Is that a 'feature' of the lvalue attribute, or something about the method?

I wouldn't expect this traditional setup to work:

sub value { my ($self, $value) = @_; if (defined $value) { $self->{value} = $value; }; }; $valobj->value(undef);

But I would've expected all the work behind :lvalue to fix that.

Updated: Yes, I've read the pod. It's experimental. Good thing they're using it. The pod doesn't really mention what would happen in the case of setting undef though.

-=Chris

Replies are listed 'Best First'.
Re: :lvalue, How I Hate Thee
by BrowserUk (Patriarch) on Aug 17, 2005 at 19:38 UTC
    At one point, I have to figure out why this didn't work:

    Define "didn't work"? In what way didn't it work?

    This compiles and runs without error:

    #! perl -slw use strict; package thing; sub new { bless {}, $_[0]; } sub value :lvalue { my $this = shift; $this->{VALUE};} package main; my $thing = thing->new; $thing->value = undef;

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

      Didn't work, as in $self->{VALUE} maintained it's original value of 'Yes', instead of being set to undef.

      What version ot perl was that under?

        5.8.4, but I think you're right that there is something else involved here.

        #! perl -slw use strict; package thing; sub new { bless { VALUE => 'YES' }, $_[0]; } sub value :lvalue { my $this = shift; $this->{VALUE}; } package main; print $]; my $thing = thing->new; print $thing->value; $thing->value = undef; print $thing->value; __END__ P:\test>junk2 5.008004 YES Use of uninitialized value in print at P:\test\junk2.pl line 22.

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

      It works on one machine, but not the other. One is perl 5.8.3 and the other is 5.8.6, but it feels like something else is afoot....

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://484548]
Approved by BrowserUk
Front-paged by zby
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2022-01-22 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (62 votes). Check out past polls.

    Notices?