Converting String Scalar Number

Problem

Converting a string scalar into a number.



Solution

To convert a string scalar to a number, just add zero.

Sometimes Perl calculations get a bit screwed, when Perl decides it is dealing with a string – not a number.



Example


Here is the code to fix it up:


print $scalar + 0;
$str+=0;



Reference

[tags]Scalars, Perl Coding School[/tags]



Leave a Reply

Your email address will not be published. Required fields are marked *