Perl/Shell Knowledge Sharing

Perl Interview Questions and Answers

Friday, March 25, 2011

How to I convert a string to a number

#How to I convert a string to a number

sub atoi {
 my $t;
 foreach my $d (split(//, shift())) {
     $t = $t * 10 + $d;
     print "$t\n";
  }
return $t;
}

$number = atoi("123");

print "string '123' number value is $number";
Posted by perlknowledge at 9:50 PM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Labels: Interview question

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Search This Blog

Blog Archive

  • ►  2017 (1)
    • ►  March (1)
  • ►  2014 (23)
    • ►  November (1)
    • ►  July (1)
    • ►  June (5)
    • ►  April (4)
    • ►  March (6)
    • ►  January (6)
  • ►  2013 (9)
    • ►  December (4)
    • ►  June (4)
    • ►  March (1)
  • ►  2012 (5)
    • ►  November (1)
    • ►  January (4)
  • ▼  2011 (215)
    • ►  November (5)
    • ►  September (1)
    • ►  August (5)
    • ►  July (11)
    • ►  June (6)
    • ►  May (17)
    • ►  April (16)
    • ▼  March (14)
      • use encoding 'utf8" example
      • use encoding 'utf8' example
      • Deleting files & directories recursively
      • The Pattern Component Order of Precedence
      • use 'eval' function in perl
      • duplicate element count in array
      • date sort in perl
      • reading .ini file without using a module
      • Tie::IxHash Example in perl
      • How to I convert a string to a number
      • How to compare 2 arrays and differences store in 3...
      • Runtime vs Compile time
      • Runtime vs Compile time
      • add module path in INC
    • ►  February (9)
    • ►  January (131)
  • ►  2010 (42)
    • ►  December (42)
Simple theme. Powered by Blogger.