Zaxo,
The body of an lvalue sub doesn't get executed when it is used as an lvalue.
Not sure if that was the original behavior back in 1999 when they were first introduced but newer versions certainly disagree with you:
my %foo;
get_set( 'foo' ) = 42;
print get_set( 'foo' );
sub get_set :lvalue {
my $key = shift;
print "key is $key\n";
my $junk;
$key eq 'foo' ? $foo{$key} : $junk;
}
__END__
key is foo
key is foo
42
...You can retrieve it with $foo->get_set($bad_key)
Where $bad_key is any and all bad keys. This is why one of the desired features would be to determine if it was in assignment or not.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|