Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Is there an elegant way of resetting the match position?

by bv (Friar)
on Oct 22, 2009 at 17:04 UTC ( #802772=note: print w/replies, xml ) Need Help??


in reply to Is there an elegant way of resetting the match position?

If you use a lookahead regex, you can avoid resetting the position after every match. But the real issue (in my mind) is that you use $&, which incurs a significant performance hit. Here's a solution that produces the same output using lookaheads and substr:

#! /usr/bin/perl -w use strict; use warnings; my $a = "Input String: aaAabBAAa"; my $n = shift @ARGV; $n --; my $rx = qr/(.)(?=\1{$n})/i; while ( $a =~ /$rx/g ) { print substr( $a, pos($a)-1, $n+1), "\n"; }

print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2020-02-19 11:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (81 votes). Check out past polls.

    Notices?