Created
November 20, 2013 20:28
-
-
Save AndrewRussellHayes/7570441 to your computer and use it in GitHub Desktop.
perl string matching with tail anchor
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/perl | |
use strict; | |
use warnings; | |
# if the string ends in z regardless of case the below returns true | |
my $string = '"abcdefz"'; | |
my $string2 = "abcefj"; | |
my $last; | |
$last = substr($string,-2,1); | |
print $last; | |
if ($last =~ /Z/i) | |
{ | |
print "yay"; | |
} | |
else | |
{ | |
print "noooo"; | |
} | |
if ($string2 =~ /Z$/i) | |
{ | |
print "yay"; | |
} | |
else | |
{ | |
print "noooo"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment