Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Which is the efficient pattern matching modifiers (s///g; or s///gs;)?

by perlsen (Chaplain)
on Apr 13, 2006 at 12:57 UTC ( [id://543059]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://543059]
Approved by socketdave
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 19:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found