Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Refer by relative way to regex group (eg. the last one)

by Anonymous Monk
on Jan 19, 2022 at 16:10 UTC ( #11140615=note: print w/replies, xml ) Need Help??


in reply to Refer by relative way to regex group (eg. the last one)

You do not say how your code fails, but if you add use strict; to your example you get

$ perl -Mstrict -Mwarnings -e 'my $word; "foobar" =~ /(oo)(bar)(?{$word=${-1}})/'
Can't use string ("-1") as a SCALAR ref while "strict refs" in use at -e line 1.

Suggestions:

$ perldoc -v '@-'
$ perldoc -v '@+'

Or, under at least Perl 5.10, you could use named captures.

Replies are listed 'Best First'.
Re^2: Refer by relative way to regex group (eg. the last one)
by LanX (Sage) on Jan 19, 2022 at 17:14 UTC
    > Suggestions:

    sigh...

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    update

    DB<29> "ab" =~ /^((.)(.))(?{say $+;say $^N; say "$1 $2 $3\n@{^CAPTUR +E}"})/ b ab ab a b ab a b

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11140615]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2022-05-23 01:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (81 votes). Check out past polls.

    Notices?