Jenda Krynicky wrote:
> 
> > How can I optimize the script for a big files ?
> >
> > ....
> 
> Change it to :
> 
> open(READ, "$ARGV[0]");
> open(WRITE,"> $ARGV[1]");
> 
> while(defined($i = <READ>)) {
>          $i =~ s/\.Cure/\.fa/g ;
>          $i =~ s/cure-/fa-/g ;
>          $i =~ s/class=Cure/class=fa/g ;
>          $i =~ s/window.name!=\"frSheet\"/false/g ;
>          print WRITE $i;
>         }
> 
> close(READ);
> close(WRITE);
> 
> Jenda

It's hard to optimize speed of the above. 
Searching and replacing of lang fixed strings is something regexp are
trained for.

You only can optimize if there are K.O.-criteria,
which are quite very fast to find.
E.g. line doesn't have to start with a blank or so.

Perhaps I see another optimization:

s/\.Cure/\.fa/g and s/cure-/fa-/g is nearly the same.
Perhaps it's an idea to make one regexp of it:

s/(\.)?([Cc]ure)(-?)/($1 || $3) ? ($1 . "fa" . $3) : "$1$2$3"/eg;

It's even possible to include the third regexp:

s/(\.|class=)? ([Cc]ure) (-?)
 /($1 || $3) ? ($1 . "fa" . $3) : "$1$2$3"/egx;

I don't know whether it's really quicker. It depends on your input. 
Just Try it.

Another kind of optimization is optimization of reading the code:

while(<READ>) {
    last unless defined;
    s/.../..../g;
    s/.../..../g
    print WRITE $_;
}

It's perhaps not necessary to handle with $i. 
Again it can increase speed, because no assignment $i = $_ is implicitly
needed.


Best Wishes,
Andrea

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to