Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
while (<DATA>) {
chomp;
print "$_ - Third character is ";
print "NOT " unless substr($_,2,1) == 8;
print "an 8.\n";
}
__DATA__
1284578898
1234587899
2189589899
3456788989
1285989899
Rate regexp substr index
regexp 218818/s -- -9% -25%
substr 239234/s 9% -- -18%
index 292398/s 34% 22% --
#!/usr/bin/perl -w
use strict;
use Benchmark qw(:all);
my @data = (1284578898, 1234587899, 2189589899, 3456788989, 1285989899 );
cmpthese(1000000,
{substr => \&substring,
regexp => \®exp,
index => \&ind });
sub substring {
return grep substr($_,2,1) eq '8', @data;
}
sub regexp {
return grep /^..8/, @data;
}
sub ind {
return grep index( $_, '8' ) == 2, @data;
}