Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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?
[Eily]: marto you just need a longer cable :P
[Corion]: marto: Yeah, but I'm somewhat wary of installing random USB drivers downloaded from mega.nz , Google Drive or whatever, so Linux wins there due to there being no conflicts and me just having to edit one text file in the worst case, to add the USB vendor
[hippo]: Long USB cable FTW.
[Corion]: Eily: I've thought of that, but I don't like running long cables through the appartment because sooner or later I'll trip over it, pulling at least one device off its stand :)
[marto]: hmm, may have to patch CPAN::Meta to move from search.cpan to metacpan in the META.json/yml files
[Corion]: marto: Heh - it seems that they plan to keep the search.cpan.org links alive for a long time. But still, I plan on moving PM to use/generate the new links
[Corion]: And I think it's better to generate links to the new world instead of keeping the older links alive by generating new versions of them ;)
[marto]: yeah, I guess it's supposed to be a permanent redirect, but better to make the move where possible

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (12)
As of 2018-05-23 09:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?