[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Bug report on 5.14b1 (fwd)



mark@cheers.jsc.nasa.gov, mac-perl@iis.ee.ethz.ch

Mark Manning writes recently:

!According to Chris Nandor:
!> 
!> #!perl
!> use Benchmark;
!> $eq = q{if($^O eq 'MacOS') {$x = 'hey1'}};
!> $re = q{if($^O =~ /mac/i ) {$y = 'hey2'}};
!> timethese(1000000,{eq=>$eq,re=>$re});
!> __END__
!> 
!> Benchmark: timing 1000000 iterations of eq, re...
!>         eq: 10 secs (10.92 usr  0.00 sys = 10.92 cpu)
!>         re: 19 secs (19.35 usr  0.00 sys = 19.35 cpu)
!
!Ah!  :-)  Thanks Chris!  :-)

Those two aren't even syntactically equivalent:

   if($^O =~ /mac/i ) {}

is more akin to:

   if($^O eq 'mac' ||
      $^O eq 'Mac' ||
      $^O eq 'mAc' ||
      $^O eq 'maC' ||
      $^O eq 'MAc' ||
      $^O eq 'mAC' ||
      $^O eq 'MaC' ||
      $^O eq 'MAC' ||
                   ) {}

I say "more akin to" since the internal regexp compilation of the //i 
may in fact employ a slightly more complex bump and grind strcmp() routine.
This stuff is qualitatively (though not too technically) described in 
J. Freidl's B<Mastering Regular Expressions> (which probably ought to be 
on your bookshelf :-).

BTW, VMS is one of my personal favorite platforms and there is a system 
call to return the OS name.  It has for at least ten 
years returned "VMS", but since about 1992 there has been a POSIX subsystem 
available and DEC likes to market the OS as "OpenVMS" (it also runs on two 
different architectures now).  Since there is no telling what a desparate 
company (DEC is still losing market share) will do to break old programs 
I *do* in fact branch in perl like so:

    if ($^O =~ /VMS/i) {}

for "production line" perl scripts that I expect (hope) will be running 
years from now on more than one platform.  Note that the types of things 
that you need such branching for are fragile commands anyway: 
system(), qx//, and the like.  Hence the minimal performance penalty 
is usually well worth the robustness.

Peter Prymmer


***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch