![]() |
|
P is for Practical | |
PerlMonks |
Re: Output minimal occurrences of matching regex(es)by choroba (Cardinal) |
on Nov 13, 2024 at 21:39 UTC ( [id://11162690]=note: print w/replies, xml ) | Need Help?? |
You cannot declare the two @regexes arrays in different scopes and then use them later. A variable declared with my only lasts up to the end of the enclosing block. You can declare the variable before the condition and only populate it depending on it: or you can use the conditional operator (the "ternary"), shown below. To match the entities involved in ;\s&, you need to extend the regex: i.e. an ampersand, not semicolon at least once, semicolon, space, and an entity again. Here's a complete example. Running it with script.pl 1.xml searches for the original regexes, specifyin any true parameter (e.g. script.pl 1.xml 1) after the file uses the modified regexes. I also added the grouping parentheses to the matching and $1 to the output to show which part of the string actually matched the regex. Update: Fixed formatting, thanks Discipulus.
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
In Section
Seekers of Perl Wisdom
|
|