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

Re^4: map and regexp. An newbie question

by anneli (Pilgrim)
on Oct 19, 2011 at 07:11 UTC ( #932311=note: print w/ replies, xml ) Need Help??


in reply to Re^3: map and regexp. An newbie question
in thread map and regexp. An newbie question

No, but I got lucky! See perlop:

If the /r (non-destructive) option is used then it runs the substitution on a copy of the string and instead of returning the number of substitutions, it returns the copy whether or not a substitution occurred. The original string is never changed when /r is used. The copy will always be a plain string, even if the input is an object or a tied variable.

This applies even when /g is being used (otherwise what use would /r be, being that it's non-destructive?).

(Edit: to clarify, no, I didn't try it, but I did upon being chastened, found that it did work, and ran to docs to find out why!)


Comment on Re^4: map and regexp. An newbie question
Select or Download Code
Re^5: map and regexp. An newbie question
by davido (Archbishop) on Oct 19, 2011 at 07:21 UTC

    Yep, you're correct.

    I created a test snippet, and uploaded it to my Linux computer (where I have 5.14 running) via sFTP, since the /r modifier isn't available on my Windows/Strawberry Perl 5.12 computer. Then I ran it by SSH'ing into the computer. And in so doing, mistakenly uploaded and tested a version that I hadn't added the /r modifier to. So when I thought I was checking, I wasn't.

    The docs.... And here I'm usually the one to have them practically memorized.

    Good job!!! Great humor.

    It reminds me of one of the great quotes from Programming Perl. The topic of discussion actually was what various Perl functions return in list and scalar context, which seems quite fitting to this conversation.

    "In general, Perl functions do exactly what you want, unless you want consistency."

    -- Larry Wall; Tom Christiansen; Jon Orwant. Programming Perl, 3rd Edition (Kindle Locations 15841-15842). O'Reilly Media.


    Dave

      Aha! At any rate, this was definitely a learning experience for me too; I was so scared when you asked if I'd tried it that I'll likely never venture into an area where I'm not 110% sure without trying first again!

      "In general, Perl operators do exactly what you want, unless you want consistency."

      This seems to hit the mark exactly! :)

      (P.S. I've had your home node bookmarked on my personal nodelet for sometime, as you have an amazing list of books I need to look at!)

        Don't be afraid to be wrong once in awhile. There are an army of friends here ready to correct you. ;)

        For the most part, we are among friends, and remember, the only person who is never wrong is Larry Wall, because when his opinion differs from everyone else's, it's everyone else who must take corrective action.


        Dave

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2014-12-21 18:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (106 votes), past polls