Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Rather interesting behavior. If you merely use @_'s magic aliasing, the results seem even stranger.

#! perl -slw use strict; sub recurse { print \$_[0]; print ">> '$_[ 0 ]'"; if( length $_[ 0 ] ) { recurse( substr( $_[ 0 ] , 1, -1 ) ); $_[0] = " ( $_[0] ) "; } print "<< '$_[0]'"; return; } my $str = 'abcdefghij'; recurse $str; print $str; __END__ SCALAR(0x8126a70) >> 'abcdefghij' LVALUE(0x8126bc0) >> 'bcdefghi' SCALAR(0x812a454) >> 'cdefgh' SCALAR(0x812a520) >> 'defg' SCALAR(0x812a5ec) >> 'ef' SCALAR(0x812a6b8) >> '' << '' << ' (' << ' ( d' << ' ( c (' << ' ( b ( c' << ' ( a ( b ( c ( ) d ) ( ) ef ) ghij ) ' ( a ( b ( c ( ) d ) ( ) ef ) ghij )

Perhaps this is a bug in the magic lvalue-ness of substr? It doesn't seem to be verifying the length of an lvalue on an lvalue, thus the shifting of the terms that appear on the right.


In reply to Re: Scalar refs, aliasing, and recursion weirdness. by !1
in thread Scalar refs, aliasing, and recursion weirdness. by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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 or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2021-10-28 07:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (95 votes). Check out past polls.

    Notices?