Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument isn't numeric - question

Why doesn't the first example output a warning?

#!/usr/bin/env perl
use warnings;
use 5.012;

my $c = "9\n";
say $c * 2;

my $d = "6a";
say $d * 2;

# 18
# Argument "6a" isn't numeric in multiplication (*) at ./perl8.pl line 9.
# 12
like image 617
sid_com Avatar asked Jun 12 '26 14:06

sid_com


1 Answers

When converting a number from a string, trailing whitespace is ignored, and newline counts as whitespace, so a warning isn't generated. Converting "9 " doesn't generate a warning either.

like image 200
hobbs Avatar answered Jun 15 '26 07:06

hobbs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!