Data Example
$VAR1 = [
[
'',
'',
'Wright',
'',
'(345) 333-4006',
'',
'bbbbb@aaaa.org',
'3228 Gun Club Road',
'',
'West Palm',
'FL',
'11111',
'',
'
Sgt., Detective
Palm Beach Co. Sheriff\'s Dept.'
],
[
'',
'',
'Mike',
'',
'(222) 444-5555',
'',
'johndoe@this.com',
'18 Blah Blah St.',
'',
'Littleton',
'CO',
'11111',
'',
'
Community Relations
Representative
ACCS'
]
];
I think that the following should work:
for (@rows) {
my @new = @{$rows[$_]};
# $new[0] should be equal to $rows[0][0]
}
Bookmarks
Various Links
Tutorial Link Nodes
Dispatching Benchmarks
use strict;
use warnings;
use Benchmark qw( cmpthese );
my $tests = -25;
my $rv = '';
######################################################################
+##########
sub array {
my $outcome = int( rand( 100 ) + 1 ); # Generate some test data.
my @outcome_tests = (
[ 97, 100, '99' ],
[ 93, 97, '95' ],
[ 85, 93, '90' ],
[ 75, 85, '80' ],
[ 65, 75, '70' ],
[ 55, 65, '60' ],
[ 45, 55, '50' ],
[ 35, 45, '40' ],
[ 25, 35, '30' ],
[ 15, 25, '20' ],
[ 7, 15, '10' ],
[ 3, 7, '05' ],
[ 0, 3, '00' ],
);
TEST: {
foreach my $test ( @outcome_tests ) {
my ($lower, $upper, $category) = @{ $test };
if (($outcome > $lower && $outcome <= $upper)) {
$rv .= $category;
last TEST;
}
}
$rv = "DSPAM_ERROR";
}
}
######################################################################
+##########
sub hash {
my $outcome = int( rand( 100 ) + 1 ); # Generate some test data.
my %h = map { $_ => 10 * int ( ( $_ + 4 ) /10 ) } 8 .. 93;
@h{1 .. 3} = (0) x 3;
@h{4 .. 7} = (5) x 5;
@h{94 .. 97} = (95) x 4;
@h{98 .. 100} = (99) x 3;
$rv .= $h{$outcome};
}
######################################################################
+##########
sub if_else {
my $outcome = int( rand( 100 ) + 1 ); # Generate some test data.
if ( $outcome > 97 ) { $rv .= "99"; }
elsif ( $outcome > 93 ) { $rv .= "95"; }
elsif ( $outcome > 85 ) { $rv .= "90"; }
elsif ( $outcome > 75 ) { $rv .= "80"; }
elsif ( $outcome > 65 ) { $rv .= "70"; }
elsif ( $outcome > 55 ) { $rv .= "60"; }
elsif ( $outcome > 45 ) { $rv .= "50"; }
elsif ( $outcome > 35 ) { $rv .= "40"; }
elsif ( $outcome > 25 ) { $rv .= "30"; }
elsif ( $outcome > 15 ) { $rv .= "20"; }
elsif ( $outcome > 7 ) { $rv .= "10"; }
elsif ( $outcome > 3 ) { $rv .= "05"; }
elsif ( $outcome > 0 ) { $rv .= "00"; }
else { $rv = "DSPAM_ERROR"; }
}
######################################################################
+##########
sub O_1_lookup {
my $outcome = int( rand( 100 ) + 1 ); # Generate some test data.
my @lookup = ( '00', map {
( $_->[2] ) x ( $_->[ 1 ] - $_->[ 0 ] )
} [ 0, 3, '00' ], [ 3, 7, '05' ], [ 7, 15, '10' ],
[ 15, 25, '20' ], [ 25, 35, '30' ], [ 35, 45, '40' ],
[ 45, 55, '50' ], [ 55, 65, '60' ], [ 65, 75, '70' ],
[ 75, 85, '80' ], [ 85, 93, '90' ], [ 93, 97, '95' ],
[ 97, 100, '99' ]
);
$rv .= $lookup[ $outcome ];
}
######################################################################
+##########
sub ternary {
my $outcome = int( rand( 100 ) + 1 ); # Generate some test data.
$rv .= $outcome > 97 ? 99
: $outcome > 93 ? 95
: $outcome > 85 ? 90
: $outcome > 75 ? 80
: $outcome > 65 ? 70
: $outcome > 55 ? 60
: $outcome > 45 ? 50
: $outcome > 35 ? 40
: $outcome > 25 ? 30
: $outcome > 15 ? 20
: $outcome > 7 ? 10
: $outcome > 3 ? '05'
: $outcome > 0 ? '00'
: q{DSPAM_ERROR};
}
######################################################################
+##########
sub binsearch {
my $outcome = int( rand( 100 ) + 1 ); # Generate some test data.
# for my $outcome (@tests) {
unless ($outcome > 0 && $outcome < 101) {
$rv = 'ERROR';
next;
}
if ($outcome < 46) {
if ($outcome < 16) {
if ($outcome < 4) {
$rv .= '00';
}
else {
$rv .= $outcome > 7 ? 10 : '05';
}
}
elsif ($outcome < 26) {
$rv .= 20;
}
else {
$rv .= $outcome > 35 ? 40 : 30;
}
}
elsif ($outcome < 76) {
if ($outcome < 56) {
$rv .= 50;
}
else {
$rv .= $outcome > 65 ? 70 : 60;
}
}
elsif ($outcome < 94) {
$rv .= $outcome > 85 ? 90 : 80;
}
else {
$rv .= $outcome > 97 ? 99 : 95;
}
# }
}
######################################################################
+##########
sub substring {
my $outcome = int( rand( 100 ) + 1 ); # Generate some test data.
# for my $outcome (@tests) {
my $sol = '000000000505050510101010101010102020202020202020303
+030303030303040404040404040405050505050505050606060606060606070707070
+707070708080808080808080909090909090909095959595999999';
if ($outcome > 0 && $outcome < 101) {
$rv .= substr($sol, $outcome, 2);
}
else {
$rv = 'ERROR';
}
# }
}
######################################################################
+##########
sub lr {
my $outcome = int( rand( 100 ) + 1 ); # Generate some test data.
# for my $outcome (@tests) {
if ($outcome > 0 && $outcome < 101) {
if ($outcome > 3 && $outcome < 7) {
$rv = '05';
}
else {
my $sol = (int(($outcome / 10) + .49) * 10);
if ($outcome > 93) {
$sol -= $outcome > 97 ? 1 : 5;
}
$rv .= $sol;
}
}
else {
$rv = 'ERROR';
}
# }
}
######################################################################
+##########
cmpthese($tests, {
array => \&array,
hash => \&hash,
if_else => \&if_else,
O_1_lookup => \&O_1_lookup,
ternary => \&ternary,
binsearch => \&binsearch,
substr => \&substring,
lr => \&lr,
});
Output:
CPU: P4 2.4GHz Xeon
Linux: Ubuntu Dapper Drake
Kernel: Linux tivo 2.6.15-26-686 #1 SMP PREEMPT Thu Aug 3 03:13:28 UTC 2006 i686 GNU/Linux
Perl: v5.8.7 built for i486-linux-gnu-thread-multi
Rate hash O_1_lookup array lr binsearch if_else ter
+nary substr
hash 4706/s -- -41% -83% -99% -99% -99%
+-99% -99%
O_1_lookup 8016/s 70% -- -72% -98% -98% -98%
+-98% -99%
array 28507/s 506% 256% -- -92% -93% -93%
+-94% -95%
lr 343279/s 7194% 4182% 1104% -- -10% -17%
+-29% -36%
binsearch 380470/s 7985% 4646% 1235% 11% -- -8%
+-22% -29%
if_else 411858/s 8651% 5038% 1345% 20% 8% --
+-15% -23%
ternary 486110/s 10229% 5964% 1605% 42% 28% 18%
+ -- -10%
substr 538280/s 11338% 6615% 1788% 57% 41% 31%
+ 11% --
This is the machine that the module will actually be running on:
CPU: P4 1.8GHz
Linux: Debian Sarge Testing/Unstable
Kernel: Linux hood 2.6.15-1-686 #2 Mon Mar 6 15:27:08 UTC 2006 i686 GNU/Linux
Perl: v5.8.8 built for i486-linux-gnu-thread-multi
Rate hash O_1_lookup array if_else binsearch ternary s
+ubstr lr
hash 2443/s -- -47% -81% -96% -96% -96%
+ -97% -99%
O_1_lookup 4603/s 88% -- -64% -92% -92% -93%
+ -95% -98%
array 12871/s 427% 180% -- -78% -78% -79%
+ -85% -94%
if_else 59519/s 2337% 1193% 362% -- -0% -3%
+ -31% -70%
binsearch 59564/s 2339% 1194% 363% 0% -- -3%
+ -30% -70%
ternary 61575/s 2421% 1238% 378% 3% 3% --
+ -28% -69%
substr 85656/s 3407% 1761% 565% 44% 44% 39%
+ -- -57%
lr 200633/s 8114% 4259% 1459% 237% 237% 226%
+ 134% --
CPU: P4 1.8GHz
Linux: Debian Sarge
Kernel: Linux knox 2.4.27-2-386 #1 Wed Aug 17 09:33:35 UTC 2005 i686 GNU/Linux
Perl: v5.8.4 built for i386-linux-thread-multi
Rate hash O_1_lookup array binsearch ternary if_else s
+ubstr lr
hash 2768/s -- -30% -78% -93% -94% -94%
+ -94% -99%
O_1_lookup 3981/s 44% -- -68% -90% -91% -91%
+ -91% -98%
array 12380/s 347% 211% -- -70% -71% -71%
+ -72% -95%
binsearch 41607/s 1403% 945% 236% -- -3% -3%
+ -7% -83%
ternary 42715/s 1443% 973% 245% 3% -- -0%
+ -5% -83%
if_else 42874/s 1449% 977% 246% 3% 0% --
+ -5% -83%
substr 44940/s 1524% 1029% 263% 8% 5% 5%
+ -- -82%
lr 248898/s 8893% 6152% 1910% 498% 483% 481%
+ 454% --
|