Skip to content

Instantly share code, notes, and snippets.

@ysasaki
Created October 23, 2010 04:19
Show Gist options
  • Save ysasaki/641766 to your computer and use it in GitHub Desktop.
Save ysasaki/641766 to your computer and use it in GitHub Desktop.
#!/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