Remix.run Logo
fanf2 8 days ago

This is one of the features that Ruby cribbed directly from Perl. The Ruby documentation seems really bad, in particular “interpolation mode” is grievously misleading.

Perl’s documentation is far more clear about the consequences:

(https://perldoc.perl.org/perlop#Regexp-Quote-Like-Operators)

   o   Compile pattern only once.

  […]

  PATTERN may contain variables, which will be
  interpolated every time the pattern search is
  evaluated, except for when the delimiter is a
  single quote. […] Perl will not recompile the
  pattern unless an interpolated variable that
  it contains changes. You can force Perl to skip
  the test and never recompile by adding a /o
  (which stands for "once") after the trailing
  delimiter. Once upon a time, Perl would recompile
  regular expressions unnecessarily, and this
  modifier was useful to tell it not to do so,
  in the interests of speed. But now, the only
  reasons to use /o are one of:

  [reasons]

  The bottom line is that using /o is almost
  never a good idea.
In the days before Perl automatically memoized the compilation of regexes with interpolation, even back in the 1990s, it said,

  However, mentioning /o constitutes a promise
  that you won't change the variables in the
  pattern. If you change them, Perl won't even
  notice.
Perl 4’s documentation is briefer. It says,

(https://github.com/Perl/perl5/blob/perl-4.0.00/perl.man#L272...)

  PATTERN may contain references to scalar
  variables, which will be interpolated
  (and the pattern recompiled) every time the
  pattern search is evaluated. […] If you want
  such a pattern to be compiled only once, add
  an “o” after the trailing delimiter. This
  avoids expensive run-time recompilations, and
  is useful when the value you are interpolating
  won't change over the life of the script.
Johnny555 8 days ago | parent | next [-]

https://perldoc.perl.org/perlre

  o  - pretend to optimize your code, but actually introduce bugs
giancarlostoro 7 days ago | parent [-]

Just add this flag for odd versioned deployments, infinity job security

alexpotato 6 days ago | parent | prev [-]

Nowadays, computers are super fast and super huge and super always available.

But even in the early 2000s, that was not the case. I know this b/c one of my first jobs out of college was to build a regex based system to analyze spam emails sent to big providers (like Yahoo and Hotmail (Microsoft)".

IIRC, we only had ONE Dell 2600 box to do all of the above with literally millions of emails and the same box did the parsing and the database storage (via MySql).

You REALLY learn what makes regexes efficient versus not and I remember reading about "/o" and testing it to see if it made a difference for what I was doing. I don't remember either way what the results were but this was def a blast from the past.

PS If you want to read more about the spam work back the, I have a Twitter thread about it here: https://x.com/alexpotato/status/1208948480867127296