Amblikai has asked for the wisdom of the Perl Monks concerning the following question:
I was knocking up some code today and i figured this was an interesting question for you guys
Essentially, i was wondering if it is possible to have subroutine references/calls inside a regexp? For example, subs that return a precompiled part of the regexp?
In other words, in entirely made up Perl, is this possible?..
#!/usr/bin/perl -w my $string="more than one part\nanother sentence more than"; sub getone {return qr/(more)/;} sub gettwo {return qr/(than)/;} my @array=$string=~/(\s&getone\s&gettwo)/g;
Obviously i've tested that and its nonsense, but is there a similar approach?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Subroutine Reference in a Regexp?
by haukex (Archbishop) on Nov 08, 2018 at 20:34 UTC | |
by Eily (Monsignor) on Nov 09, 2018 at 16:59 UTC | |
by haukex (Archbishop) on Nov 10, 2018 at 14:44 UTC | |
by Amblikai (Scribe) on Nov 08, 2018 at 20:39 UTC | |
|
Re: Subroutine Reference in a Regexp?
by jwkrahn (Abbot) on Nov 09, 2018 at 01:57 UTC | |
|
Re: Subroutine Reference in a Regexp?
by Eily (Monsignor) on Nov 09, 2018 at 17:10 UTC |