Bliss has asked for the wisdom of the Perl Monks concerning the following question:

if ($digit > 3) { print "$digit" . "th"; }
Anyway to write it with an escape character or null character to break up the scalar from the suffix (instead of using the dot operator)?
as in:
if ($digit > 3) { print "$digit[somemagicalnonprintingcharacter]th"; }
Thanks.

Replies are listed 'Best First'.
Re: Simple question
by arturo (Vicar) on Apr 23, 2001 at 23:01 UTC

    Sure is : print "${digit}th" if $digit > 3;

    HTH.

Re: Simple question
by indigo (Scribe) on Apr 24, 2001 at 00:14 UTC
    arturo answered the question you asked, but this might be a better way of doing what you are doing:
    my %cardinal = ( 1 => '1st', 2 => '2nd', 3 => '3rd', map { $_ => "${_}th" } 4 .. 9 ); print $cardinal{$digit};
Re: Simple question
by Bliss (Novice) on Apr 24, 2001 at 21:46 UTC
    Buddha's name be praised! You are all too kind. Thank you.