in reply to Extract last two digits from numbers

No need to use a regex: $lasttwo=substr($number,-2,2)

And it works for any length of number. It works even for non-numerical strings (Is that a bug or a feature?)

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Replies are listed 'Best First'.
Re: (2) Extract last two digits from numbers
by BrowserUk (Patriarch) on Jan 06, 2004 at 11:10 UTC

    There is no need for the third parameter there

    my $s= '12345'; print substr $s, -2; 45

    Of course, it doesn't hurt either :)


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Hooray!