I started rereading Learning Perl 3 again (though I still must say I'm not impressed with the book in its entirety) and came across a few questions regarding chapters 9 and 10. This is where they start talking about using backreferences and memory variables.

The book gives the examples below but I don't understand what the number in the \ / is doing at the end and how it's changing the results. Can someone (in different words than the book describes) explain what the purpose of this number is and how it's effecting the two lines below?

I understand the number is the reference to the block of parenthesis in chronological order. \1/ takes the data stored in (fred|wilma) which is either fred or wilma. But outside of that, I am really confused with this.

/((fred|wilma) (flintstone) \2/ could be fred flinstone fred /((fred|wilma) (flintstone) \1/ could be fred flinstone fred flinstone
In chapter 10 it goes back into memory variables using $1..whatever which I understand, but it no longer uses the numbers in \1/ or \2/ as it did earlier. Why is that?
if ($wilma =~ /(\w+)/) { print "Wilma's word was $1"; }
Thanks for your all your wisdom!

"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

In reply to memory variables (chp. 9 & 10 Learning Perl 3) by sulfericacid

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.