For those of you that are interested, I benchmarked a few of the
suggestions.  Drieux is by a significant margin the winner speed-wise.
What I did was split the scalar into an array and then define the four
variables by join()ing the result using an array slice instead of making
a new array.  Running this code, cutting out the print statements:

###################################################

use strict;
use warnings;
use Benchmark;

my $mine = timethese(1000000, {Mine => sub{
        
        my $string = '0.0.0.0.1.10.1.30.1.10.1.30.1';
        
        my @nums = split(/\./,$string);
        
        my $first = join('.',@nums[0..3]);
        my $second = $nums[4];
        my $third = join('.',@nums[5..8]);
        my $fourth = join('.',@nums[9..12]);
        
},Drieux => sub{
        
        my $input = '0.0.0.0.111.10.1.30.1.10.1.30.1 ';
        
        my $dot_quad = qr/\d+\.\d+\.\d+\.\d+/;
        
        my ($im, $jm , $km, $mm ) =
                $input =~
/($dot_quad)\.(\d+)\.($dot_quad)\.($dot_quad)/;

},Wags => sub{
        $_ = '0.0.0.0.1.10.1.30.1.10.1.30.1';

my @MyWorka = ();
@MyWorka = split(/\./, $_);
my @MyWorkb = ();
my @MyWorkc = ();
my @MyWorkd = ();

@MyWorkb = splice(@MyWorka,-4,4);
@MyWorkc = splice(@MyWorka,-4,4);
@MyWorkd = splice(@MyWorka,-1,1);

}});

#####################################################

Gave me this result:

 Benchmark: timing 1000000 iterations of Drieux, Mine, Wags...
    Drieux:  9 wallclock secs ( 8.16 usr +  0.00 sys =  8.16 CPU) @
122518.99/s (n=1000000)
      Mine: 12 wallclock secs (11.76 usr +  0.00 sys = 11.76 CPU) @
85055.71/s (n=1000000)
      Wags: 14 wallclock secs (14.53 usr +  0.00 sys = 14.53 CPU) @
68818.39/s (n=1000000)



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to