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

Comment on

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

[ Update: The end of the post I replied to, starting at "It does have its limitations though" was not present when I replied (nor during the several times I had reason to load a page that included that node during the time I took composing my reply -- I don't believe it was even present immediately after I replied; though I am less sure of that). FYI. ]

Do you know that a reference to substr works as you described?
Only if you use a single substring.
They long since fixed the 'only one lvalue ref' limitation.

Thanks for the notice, but that isn't what I was talking about. Being able to have more than one lvalue substr ref doesn't itself result in "multiple simultaneous substrings of the same string such that they cooperate" nor to them "working as the OP described". (Nor does it lead to any particularly "tricky bits", certainly not any that qualify as "fun to hash out".)

#!/usr/bin/perl -w use strict; my $s = 'one,two,three,four'; my @p; while( $s =~ /([^,]+)/g ) { push @p, \substr( $s, pos($s)-length($1), length($1) ); } print "($$_)" for @p; print " [$s]\n"; ${$p[0]} = 'five'; # Change 'one' to 'five' ${$p[2]} = 'X'; # Change 'three' to 'X' print "($$_)" for @p; print " [$s]\n"; print $], $/; __END__ (one)(two)(three)(four) [one,two,three,four] (five)(,tw)(X)(r) [five,twoXe,four] 5.012000

While the OP was requesting an outcome like:

(five)(two)(X)(four) [five,two,X,four]

Note that I'm not trying to argue that \substr magic should be taught to "cooperate". What \substr magic does is quite simple and sane and I see no reason to change it. It just doesn't match what the OP was asking for (nor what my module implements).

- tye        


In reply to Re^4: Is there a module for object-oriented substring handling/substitution? (cooperate) by tye
in thread Is there a module for object-oriented substring handling/substitution? by smls

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (5)
    As of 2014-08-23 07:40 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (172 votes), past polls