You have sort of copied an example straight out of the Perlretut without really understanding what it does.

I would say that not everything that you read in the tutorials is common - there are some very complicated and rare things - and this is one of them!

This is so rare, that I don't think that it is worth delving into the mind-numbing details. VERY seldom do you even care in the slightest about the pos(position) of a match - that is 'C' thinking.

Perl regex is most commonly used to capture stuff that is between other stuff and whether this happens at index 5 or 95 usually just doesn't make any difference at all. The purists would say: "well sometimes it does matter" and I would agree with them. What I am saying here is that the pos() almost always does not matter.

I show some more common ideas in Perl below.

#!usr/bin/perl use warnings; use strict; my $x = "Mmm...donut, thought... Homer...Yech...peas"; my @matches = $x =~ /(Mmm|Yech)\.\.\.(donut|peas)/g; print "number of matches is: ".@matches."\n"; print "matches are: @matches\n"; print "\n"; $x = "MmmABCdonut, thought... HomerABXYechABYpeas"; my @moreMatches = $x =~ /(?:Mmm|Yech)(...)(?:donut|peas)/g; print "moreMatches number: ".@moreMatches,"\n"; print "@moreMatches\n"; __END__ prints: number of matches is: 4 matches are: Mmm donut Yech peas moreMatches number: 2 ABC ABY

In reply to Re: can't use string refs while "strict refs" by Marshall
in thread can't use string refs while "strict refs" by artifact

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.