Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Simple question

by Bliss (Novice)
on Apr 23, 2001 at 23:00 UTC ( [id://74820]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://74820]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-24 01:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found