Converting String Scalar Number

[problem]

Converting a string scalar into a number.

[/problem]

[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.

[/solution]

[example]

Here is the code to fix it up:


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

[/example]

[reference]

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

[/reference]

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

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