Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: •Re: Find illegal ASCII characters

by Anonymous Monk
on Mar 07, 2002 at 22:40 UTC ( #150168=note: print w/replies, xml ) Need Help??

in reply to •Re: Find illegal ASCII characters
in thread Find illegal ASCII characters

 while (/([^\n\r\x20-\x7f])/g) {

Why not to fix the expresion "once" to make the script faster?

  while (/([^\n\r\x20-\x7f])/go) {


Replies are listed 'Best First'.
Re: Re: •Re: Find illegal ASCII characters
by demerphq (Chancellor) on Mar 08, 2002 at 19:09 UTC
      I was going to answer something like that, but forgot all about it. In the meantime, I've read (once again) some parts of, and found these interesting regexes:

      $toencode =~ s{&}{&amp;}gso; $toencode =~ s{<}{&lt;}gso; $toencode =~ s{>}{&gt;}gso; $toencode =~ s{"}{&quot;}gso; ... $toencode =~ s{'}{&#39;}gso; $toencode =~ s{\x8b}{&#139;}gso; $toencode =~ s{\x9b}{&#155;}gso; ... $toencode =~ s{\012}{&#10;}gso; $toencode =~ s{\015}{&#13;}gso;

      That's at least 9 uses of /o with no variable interpolation in the pattern.

      But CGI also doesn't use strict, has no spaces after commas, uses C-style for-loops where lists where more efficient and better readable, assumes that the IP address "0" equals "", has ugly #-laden comments, etc... So is the use of /o really more efficient when no variable interpolation is used, or is this yet another strange thing in (Excuse me for being so negative about, but having read it, I prefer my own set of functions even more.)


        Adding /o to regexps with no variable interpolation doesn't hurt anybody. It just ignored. I don't think it can be counted as bad style since there is no anything bad in doing it.

        Ilya Martynov (

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2020-10-31 17:32 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (290 votes). Check out past polls.