Regexp capture group list
Paul LeoNerd Evans
leonerd at leonerd.org.uk
Tue Nov 10 14:53:28 GMT 2009
(appols for semi-duplicate)
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.
In fact, they seem to behave quite similarly:
$ perl -MDevel::Peek -e 'my $foo = "abcde"; substr( $foo, 0, 3 ) = ""; Dump $foo'
SV = PVIV(0x8e50d0) at 0x8d2e38
REFCNT = 2
FLAGS = (PADMY,POK,OOK,pPOK)
IV = 3 (OFFSET)
PV = 0x8ea143 ( "abc" . ) "de"\0
CUR = 2
LEN = 5
$ perl -MDevel::Peek -e 'my $foo = "abcde"; $foo =~ s/^abc//; Dump $foo'
SV = PVIV(0x1bc90d0) at 0x1bb6e38
REFCNT = 1
FLAGS = (PADMY,POK,OOK,pPOK)
IV = 3 (OFFSET)
PV = 0x1bce133 ( "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/a8ae4ded/attachment.pgp
More information about the london.pm
mailing list