Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Fast Replacement

by muba (Priest)
on Jun 14, 2013 at 05:21 UTC ( #1038886=note: print w/replies, xml ) Need Help??


in reply to Fast Replacement

The reason it is slow is that for every call to index, Perl has to go through the process of checking each character in the string whether it is an "!". Again and again and again. So you could use the $index variable to tell Perl not to bother about the characters it has already checked:

while ( index($group, "!", $index) > -1 and $index<50000 ) {

Alternatively, because TIMTOWTDI:

use strict; use warnings; my $string = "abc!def!ghi!jkl!mno!pqr!stu!vwx!yz"; my $limit = 3; $string = join("\n", split(/!/, $string, $limit)); print $string;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2019-04-23 19:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I am most likely to install a new module from CPAN if:
















    Results (118 votes). Check out past polls.

    Notices?