Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

by sleepingsquirrel (Chaplain)
on Feb 05, 2005 at 01:14 UTC ( [id://428265]=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.

Still probably not what you are looking for (i.e. no refs), but closer maybe? (at least no regex)
#!/usr/bin/perl -slw use strict; my $str = 'aaaaaaaaaa'; print recur($str); sub recur { my $s = shift; return "" if length($s)==0; substr($s,1,-1) = recur(substr($s,1,-1)); return "($s)"; }


-- All code is 100% tested and functional unless otherwise noted.

Replies are listed 'Best First'.
Re^4: Scalar refs, aliasing, and recursion weirdness.
by BrowserUk (Patriarch) on Feb 05, 2005 at 01:45 UTC
    Still probably not what you are looking for (i.e. no refs)

    The refs were only a half-arsed attempt to get thing to work when I suspected that the @_ aliasing was responsible for "undo" my changes--a total wrong guess!

    And, your post has moved me along considerably. Your insight of using the same substr as an lvalue into which to assign the return from the recusion--with the same parameters as are used to supply the substring to that level of recursion is (I think) the solution.

    I've put that into the real code and it gets me closer to the desired result. At this stage, the rest of the problem appears to down to my selecting the correct substring--ie. a completely different part of the problem.

    So thankyou. Very much.


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-28 10:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found