"be consistent" PerlMonks

### Re^2: Scalar refs, aliasing, and recursion weirdness.

by BrowserUk (Pope)
 on Feb 04, 2005 at 23:33 UTC ( #428246=note: print w/replies, xml ) Need Help??

I think you may have hit the nail on the head.

It would appear that if you modify an lvalue ref, it gets converted to a normal scalar before the modification.

Which is annoying and counter-intuative (to me anyway), but maybe work that would be involved in allowing the underlying scalar to be modified through a substring of an lvalue ref is too complicated?

Maybe I will have to code my own lvalue-ref-on-steroids to achieve my purpose?

Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.
• Comment on Re^2: Scalar refs, aliasing, and recursion weirdness.

Replies are listed 'Best First'.
Re^3: Scalar refs, aliasing, and recursion weirdness.
by !1 (Hermit) on Feb 04, 2005 at 23:38 UTC

Even better example:

```#! perl -slw
use strict;

sub recurse {
print ">> '\${ \$_[ 0 ] }'";
(my \$depth=\$_[1])--;
if (\$depth) {
recurse( \ substr( \${ \$_[ 0 ] }, 1, -1 ), \$depth );
}
else {
\${\$_[0]} = "XX";
}
print "<< '\${ \$_[ 0 ] }'";
return;
}

my \$str = 'abcdefghi';

recurse \\$str, 3;
print \$str;

recurse \\$str, 2;
print \$str;

__END__
>> 'abcdefghi'
>> 'bcdefgh'
>> 'cdefg'
<< 'XX'
<< 'bcdefgh'
<< 'abcdefghi'
abcdefghi
>> 'abcdefghi'
>> 'bcdefgh'
<< 'XXi'
<< 'aXXi'
aXXi

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://428246]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2021-09-23 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?