Edwards, Mark (CXO) writes:
 > 
 > Either substr() or unpack().  unpack() is probable more efficient.

You should probably check before you make such statements. The
following code:

use strict;
use Benchmark;

my $count = 1000000;
my $data = "abcdefghijklmnopqrstuvwxyz";

timethese($count,
         {'unpack' => sub {my ($v1, $v2, $v3) = unpack "C3C6C10", $data;},
          'substr' => sub { my $v1 = substr($data,0,3);
                            my $v2 = substr($data,3,6);
                            my $v3 = substr($data,9,10);}
          }
         );

Produces:

Benchmark: timing 1000000 iterations of substr, unpack...
    substr: 13 wallclock secs (10.03 usr +  0.00 sys = 10.03 CPU) @ 99700.90/s 
(n=1000000)
    unpack: 34 wallclock secs (27.69 usr +  0.00 sys = 27.69 CPU) @ 36114.12/s 
(n=1000000)

Unless, of course, you some other definition of 'efficient'.

-- 
Brian Raven
A "goto" in Perl falls into the category of hard things that should be
possible, not easy things that should be easy.
             -- Larry Wall in <[EMAIL PROTECTED]>
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl

Reply via email to