Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

zejames's scratchpad

by zejames (Hermit)
on Sep 14, 2004 at 11:31 UTC ( [id://390801]=scratchpad: print w/replies, xml ) Need Help??

#!/usr/bin/perl # use Benchmark qw/ cmpthese /; open F, "conf/English/stops" or die "Pb : $!\n"; chomp(@stops = <F>); open G, "test/texte" or die "Pb : $!\n"; chomp(@text = <G>); for $line (@text) { push @data, split /\s+/, $line } %seen = map { $_ => 1 } @stops; my @regexens = map { qr/\Q$_\E/ } @stops; { local $" = '|'; $r = qr/@regexens/; } cmpthese(100, { 'string' => sub { WORD: foreach my $word (@data) { foreach my $stop (@stops) { next WORD if ($stop eq $word); } push @words, $word; } }, 'regex' => sub { WORD2: foreach my $word (@data) { next WORD2 if ($word =~ m/^$r$/); push @words, $word; } }, 'hash' => sub { WORD: foreach my $word (@data) { next WORD if $seen{$word}; push @words, $word; } } }); __DATA__ (warning: too few iterations for a reliable count) Rate string regex hash string 30.0/s -- -70% -99% regex 99.9/s 233% -- -97% hash 3704/s 12230% 3607% --

package Letter; use overload '+' => \&do_plus, '-' => \&do_minus, '""' => \&do_print; sub new { my ($ref, $letter) = @_; bless [ $letter ], $ref; } sub do_plus { my $self = shift; my $plus = shift; $self->[0] = chr(ord($self->[0]) + 1); } sub do_minus { my $self = shift; my $plus = shift; $self->[0] = chr(ord($self->[0]) - 1); } sub do_print { my $self = shift; $self->[0]; } package main; my $l = new Letter("F"); $l--; print $l;

Funny :

$#a = 0 or $#a = -1 autovivifies @a

$#a >>= 1 does not
-1 >>= 1 gives, on my computer 2147483647
$#a = 2147483647 does not either

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-25 05:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found