in reply to Extract last two digits from numbers
Cheers - L~R#!/usr/bin/perl -w use strict; my $number = 1234; my $last2; if ( $number =~ /^\d\d(\d\d)$/ ) { $last2 = $1; } print "$last2\n" if defined $last2;
Update: Regular expressions can be tricky as can be the notion of what constitutes a "number". You might also want to take a look at Mastering Regular Expressions and Scalar::Util's looks_like_number function for some more advanced stuff.
|
|---|