in reply to Re^8: Reusing a complex regexp in multiple spots, escaping the regexp
in thread Reusing a complex regexp in multiple spots, escaping the regexp
That was my first intuition, and looks like we were right, the final program is the same for the flattened string.
$ perl -Mre=debug -E'$x=qr/[X0-9a-f]/i; $hr=qr/$x+ - $x+/x;' Compiling REx "[X0-9a-f]" Final program: 1: ANYOF[0-9A-FXa-fx] (11) 11: END (0) stclass ANYOF[0-9A-FXa-fx] minlen 1 Compiling REx "(?^ui:[X0-9a-f])+ - (?^ui:[X0-9a-f])+" Final program: 1: PLUS (12) 2: ANYOF[0-9A-FXa-fx] (0) 12: EXACT <-> (14) 14: PLUS (25) 15: ANYOF[0-9A-FXa-fx] (0) 25: END (0) floating "-" at 1..9223372036854775807 (checking floating) stclass ANY +OF[0-9A-FXa-fx] plus minlen 3 Freeing REx: "(?^ui:[X0-9a-f])+ - (?^ui:[X0-9a-f])+" Freeing REx: "[X0-9a-f]" $
$ perl -Mre=debug -E'$hr=qr/(?^ui:[X0-9a-f])+ - (?^ui:[X0-9a-f])+/x;' + Compiling REx "(?^ui:[X0-9a-f])+ - (?^ui:[X0-9a-f])+" + Final program: 1: PLUS (12) 2: ANYOF[0-9A-FXa-fx] (0) 12: EXACT <-> (14) 14: PLUS (25) 15: ANYOF[0-9A-FXa-fx] (0) 25: END (0) floating "-" at 1..9223372036854775807 (checking floating) stclass ANY +OF[0-9A-FXa-fx] plus minlen 3 Freeing REx: "(?^ui:[X0-9a-f])+ - (?^ui:[X0-9a-f])+" $
> the regexp would need to be compiled each time around the while loop
I think that's what /o was invented for
So... Consequently any performance penalty coming with qr// could be mitigated by flattening it first and using the resulting string with /o modifier. 🤔
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^10: Reusing a complex regexp in multiple spots, escaping the regexp
by tobyink (Canon) on Apr 16, 2026 at 15:05 UTC | |
by LanX (Saint) on Apr 16, 2026 at 17:01 UTC | |
by tobyink (Canon) on Apr 17, 2026 at 08:15 UTC | |
by sleet (Pilgrim) on Apr 17, 2026 at 10:02 UTC | |
by LanX (Saint) on Apr 17, 2026 at 11:32 UTC | |
| |
by LanX (Saint) on Apr 17, 2026 at 11:36 UTC | |
by tobyink (Canon) on Apr 17, 2026 at 14:03 UTC | |
|