Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String to number conversion

Status
Not open for further replies.

Meatsim

Programmer
Oct 9, 2001
13
US
Hello folks! Is there a function that converts a string to a number (or integer, or real) in perl? I'm trying to look it up in the perl book I have, but it's the classic "looking up a word you can't spell in the dictionary" problem.

Thanks!

-Meatsim
 
You shouldn't have to worry about it. If you use a string that contains a number as if it were a number, perl will treat it as a number. perl doesn't strongly type anything, so there's really no such thing as integers or reals in perl either - they're all treated as floating point numbers. For example, this code will work fine:
Code:
$pi = "3.14159";
$radius = "2";
$area = $pi * $radius * $radius;
If you need to strip out non-numeric characters first, you can use a regular expression to do that. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top