perlsen has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

For Large text file processing purpose,
I have two types of statement options with differnt pattern modifiers for find and replace.
$string =~ s/find /replace/g; $string =~ s/find /replace/gs;

please suggest me a better statement among those for code optimization.
Which is the efficient statement that is less time consuming? and also please explain me
the difference between those two statements?
open (FIN, "$inputfile") || die("Cannot read the input file"); local $/; $string = <FIN>; close FIN; $string =~ s/find /replace/g; #and $string =~ s/find /replace/gs;

Welcomes your ideas
Perlsen

Replies are listed 'Best First'.
Re: Which is the efficient pattern matching modifiers (s///g; or s///gs;)?
by Fletch (Bishop) on Apr 13, 2006 at 13:06 UTC

    If you'd bother to read perlre it quite clearly states that the only thing the /s modifier does is change the meaning of a "." to also match a \n character. That's in no way going to affect performance meaningfully.

      Ohh!!..ok.
      Thanks for your great suggetions.

      regards,
      perlsen
Re: Which is the efficient pattern matching modifiers (s///g; or s///gs;)?
by Anonymous Monk on Apr 13, 2006 at 13:16 UTC
    and you can easily determine for youself which of several methods is faster by using the Benchmark module
Re: Which is the efficient pattern matching modifiers (s///g; or s///gs;)?
by QM (Parson) on Apr 14, 2006 at 16:41 UTC
    TIAS: Try It And See.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of