in reply to •Re: A pattern that matches three consecutive copies...
in thread A pattern that matches three consecutive copies...

In the book under appendix A it says: Here is one way to do it:
/($what){3}/
so this is what I tried to do in my script:
#!/usr/bin/perl -w use strict; my $what = 'fred|barney'; if($what =~ /($what){3}/){ print "$&"; } else{ print "no match\n"; }

Replies are listed 'Best First'.
•Re: Re: •Re: A pattern that matches three consecutive copies...
by merlyn (Sage) on Jun 09, 2002 at 15:58 UTC
    Well, fred|barney as a string doesn't have three things that match the regex (fred|barney) in a row. So I would expect it to say "no match". Are you getting something different from that?

    -- Randal L. Schwartz, Perl hacker

      Yes actually I am getting it to say no match. Thats what I expect it get too! So I guess I don't uderstand the question in the book then...
        Three consecutive copies of the regex fred|barney would be like:
        fredfredfred fredbarneyfred barneybarneybarney
        and so on. Put one of those as your string on the left of the =~ operator, and it'll match!

        -- Randal L. Schwartz, Perl hacker