Created
October 23, 2010 04:19
-
-
Save ysasaki/641766 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Test::More tests => 3; | |
my $xxx = "a"; | |
my $str = "aaabbbaaabbb"; | |
my $hit = 6; | |
diag "str => $str, char => $xxx, hit => $hit"; | |
my $eval = eval "\$str =~ tr/$xxx//"; | |
is( $eval, $hit, "using eval count => $eval" ); | |
diag "next code does not work. see perldoc perlop for detail"; | |
my $noeval = $str =~ tr/$xxx//; | |
is( $noeval, $hit, "no eval count => $noeval" ); | |
my $count = $str =~ s/($xxx)/$1/g; | |
is( $count, 6, "using s///g count => $count" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment