Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

zejames's scratchpad

by zejames (Hermit)
on Sep 14, 2004 at 11:31 UTC ( #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
Chatterbox?
[Discipulus]: who make the invitation? the program?!?
[choroba]: it's historical
[erix]: pull requests
[choroba]: originally, you sent a pull request to someone by email, i.e. you asked them to pull from your repo
[Discipulus]: if is the author of a patch, is more like a 'request to push' into rather than a pull request..
[choroba]: as it's considered unpolite to push to someone else's repo
[choroba]: and in fact, you don't push into the target repo, you push into your branch of your fork
[choroba]: the maintainer of the upstream repo than "merges" the pull request, i.e. they pull from your fork into the upstream
[Discipulus]: ' i.e. you asked them to pull from your repo' =~ I (subj) want to push
[Discipulus]: chorobayour words are reasonable

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2017-05-27 20:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?