Regexp capture group list

Paul LeoNerd Evans leonerd at leonerd.org.uk
Tue Nov 10 14:37:00 GMT 2009


On Tue, Nov 10, 2009 at 03:11:04PM +0100, Philip Newton wrote:
> On Tue, Nov 10, 2009 at 14:51, Paul LeoNerd Evans
> <leonerd at leonerd.org.uk> wrote:
> > So how about
> >
> >  my @matches = $_[0] =~ m/^$re/ or die ....;
> >  substr( $_[0], 0, $+[0] ) = "";
> >
> >  return @matches;
> >
> > I think I like that...
> 
> Ooh, yes, it does have a certain charm. And it may even involve less
> string copying -- I don't know whether s/^.....// is optimised to do
> that, but AFAIK substr( ..., 0, ... ) = "" will simply set the
> internal OFFSET flag in the SV.

Seems to:

$ perl -MDevel::Peek -e 'my $foo = "abcde"; substr( $foo, 0, 3 ) = ""; Dump $foo'
SV = PVIV(0xf370d0) at 0xf24e38
  REFCNT = 2
  FLAGS = (PADMY,POK,OOK,pPOK)
  IV = 3  (OFFSET)
  PV = 0xf3c143 ( "abc" . ) "de"\0
  CUR = 2
  LEN = 5


-- 
Paul "LeoNerd" Evans

leonerd at leonerd.org.uk
ICQ# 4135350       |  Registered Linux# 179460
http://www.leonerd.org.uk/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: Digital signature
Url : http://london.pm.org/pipermail/london.pm/attachments/20091110/7879e51e/attachment.pgp


More information about the london.pm mailing list