Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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 having an uproarious good time at the Monastery: (6)
As of 2019-12-08 22:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?