> > On Thu, 25 Aug 2011 10:42:20 +0200
> > Honza Mach <jan.m...@cesnet.cz> wrote:
> > 
> > > Hi everybody,
> > > 
> > > I was wondering, if it is possible to use backreferences in the pattern
> > > repetition bracket operator.
> > > 
> > > Consider the following string:
> > > 
> > > my $string = "5 abcdefghijklmn";
> > > 
> > > The number five at the beginning of the string means, that I want to
> > > extract first five characters from the latter part of the string. I
> > > tried the following code, but it doesn`t work:
> > > 
> > > $string =~ s/(\d+)\s+(.{\g1})//;
> > > print "extracted: $1 $2\n";
> > > 
> > > The desired output would be:
> > > 
> > > extracted: 5 abcde

Something like this will work:

  say "extracted: ", /^(\d+\s+.{$len})/ if ($len) = /^(\d+)/

Sometimes two passes are are better than one.

-- 
Paul Johnson - p...@pjcj.net
http://www.pjcj.net

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to