On 8/25/07, Rodrigo Tavares <[EMAIL PROTECTED]> wrote:

> In many languages there is a function for convert int
> for string. Ho I can do it in Perl ?

It's so easy to put a number into a string, we don't have a function
for it. We simply interpolate:

  my $age = 6 * 7; # or any other number
  print "I'm $age years old.\n";

The number in $age is converted to a string form ("42") and
interpolated into the string, which is then printed. Is that what you
were needing?

When you need more control over how numbers become strings, printf and
its cousin sprintf offer many flexible options. For example, it's nice
to have leading zeroes when formatting minutes and seconds:

  # Result looks like " 1:02:03"
  my $hhmmss = sprintf "%2d:%02d:%02d", $h, $m, $s;

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to