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

Re: Where can I find more examples of use of Special Backtracking Control Verbs?

by rsFalse (Friar)
on Nov 06, 2018 at 19:33 UTC ( #1225323=note: print w/replies, xml ) Need Help??


in reply to Where can I find more examples of use of Special Backtracking Control Verbs?

I usually use '(*FAIL)' with '(?{})' to generate all possible substrings of the string, or in similar cases. E.g.
my $string = <>; my %substrings; $string =~ /(.+)(?{ $substrings{ $1 } = 1 })(*FAIL)/;
E.g. to calculate some statistics:
/ (\b\d+\b) .*? (\b\d+\b) (?{ $count += $1 > $2 }) (*FAIL) /x;
But have no experience of using PRUNE, SKIP and others :)

Replies are listed 'Best First'.
Re^2: Where can I find more examples of use of Special Backtracking Control Verbs?
by rsFalse (Friar) on Nov 07, 2018 at 12:30 UTC
    Also once I used '(?{})' with '(*FAIL)' simply for traversing all characters of the string.
    /.(?{ do_smth( $& ) })(*FAIL)/ for @lines;
    This part:
    /.(?{ do_smth( $& ) })(*FAIL)/
    is similar to:
    do_smth( $& ) while /./g;
    , but it can not(?) be combined with 'for' into one short expression like:
    do_smth( $& ) while /./g for @lines; # syntax error
    Instead I should write:
    do{ do_smth( $& ) while /./g } for @lines;
    Another variant here was to concatenate all lines: my $concatenated_lines = join $some_concatenator, @lines. And then simply match. But imagine if the regex is more complex and can accidentally match a concatenator as well.
    And another alternative here was to use eval within non-destructive substitution:
    s/./ do_smth( $& ) /ger for @lines;
    Note modifiers: e - for eval, and r - for non-destructiveness.
    But imagine do_smth function returning long strings (e.g. ( ( ord $& ) % 2 ? $odds : $evens ) .= $& ) and it could possibly(?) slow down process.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2019-10-16 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?