Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by sleepingsquirrel (Hermit)
on Feb 05, 2005 at 01:14 UTC ( #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.


Comment on Re^3: Scalar refs, aliasing, and recursion weirdness.
Download Code
Re^4: Scalar refs, aliasing, and recursion weirdness.
by BrowserUk (Pope) 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
Node Status?
node history
Node Type: note [id://428265]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2014-11-21 02:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (104 votes), past polls