Very close but you can't do it quite that way. Here is your code in working form:
$source =~ m!(\d{1,2})[-/](\d{1,2})[-/](\d{2,4})!g; my $day = $1; if( $day == 1 or $day == 21 or $day == 31 ){ $day .= 'st'; }elsif( $day == 2 or $day == 22 ){ $day .= 'nd'; }elsif( $day == 3 or $day == 23 ){ $day .= 'rd'; }else { $day .= 'th'; }
I have shown you the use or character classes and different regex delimiters (you can use ! or anything else for that matter, not just /) as well as the .= operator. A little indenting makes it easier to read. The last case is just an else as we want to catch everything that is not a st/nd/rd with th
This also works and demonstrates an alternative to the if elseif else structure for simple stuff
$day .= ( $day == 1 or $day == 21 or $day == 31 ) ? 'st' : ( $day == 2 or $day == 22 ) ? 'nd' : ( $day == 3 or $day == 23 ) ? 'rd' : 'th';
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
In reply to Re: pattern matching
by tachyon
in thread pattern matching
by r_mehmed
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |