Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^3: Scalar refs, aliasing, and recursion weirdness.

by MarkusLaker (Beadle)
on Feb 06, 2005 at 23:46 UTC ( #428536=note: print w/replies, xml ) Need Help??

in reply to Re^2: Scalar refs, aliasing, and recursion weirdness.
in thread Scalar refs, aliasing, and recursion weirdness.

diotalevi writes:

Marcus, you are incorrect when you summarize the documentation as noting that modifying a reference taken to a substring is forbidden. That's wrong.

You're right. I expressed myself so badly that what I wrote was factually wrong. I'll update my original response. Thanks for pointing out my mistake.

Incidentally, though, as long as no substr is involved, you can run as many substitutions as you wish on an indirected reference. Hence:

[~/perl/monks]$ ./test abc [~/perl/monks]$ cat test #!/usr/bin/perl -l use warnings; use strict; my $a = 'aaa'; $_ = \$a; $$_ =~ s/aa/ab/; $$_ =~ s/ba/bc/; print $$_; [~/perl/monks]$

That $_ = \$_ construction is interesting. It yields a variable for which $_ == $$_ == $$$_, etc. No matter how many times you indirect it, the type and value of $_ don't change. There must be some code that breaks when you do that!


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://428536]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2023-03-28 08:59 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (66 votes). Check out past polls.