Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

0+$1 for numeric, why?

by nop (Hermit)
on Dec 01, 2000 at 23:56 UTC ( #44444=perlquestion: print w/replies, xml ) Need Help??
nop has asked for the wisdom of the Perl Monks concerning the following question:

When I run this snippet
... elsif (/size(\d+)/) { $format->set_size($1); } else ...
I get this error (under strict, warnings, and diagnostics)
Argument "_size" isn't numeric in multiplication (*) at D:/Perl/site/lib/Spreadsheet/Format.pm line 225 (#1) (W numeric) The indicated string was fed as an argument to an oper +ator that expected a numeric value instead. If you're fortunate the message will identify which operator was so unfortunate.
I can force $1 to be numeric by writing
$format->set_size(0+$1);
but why do I have to do this?

Replies are listed 'Best First'.
Re: 0+$1 for numeric, why?
by chipmunk (Parson) on Dec 02, 2000 at 00:03 UTC
    I think that this warning is not caused by that snippet of code. At line 225, Spreadsheet::Format is trying to multiply the string "_size" by something. Your code snippet only calls set_size($1) when $1 contains a string of digits, so it could not be calling set_size("_size"). (If it were, adding 0 first would just get you a warning for the addition instead.)

    Can you edit Spreadsheet/Format.pm and see what is happening at line 225?

      Here's the line from Format.pm...
      $dyHeight = $self->{_size} * 20;
      But I am not sure I fully understand your comment....?
        If you look back at the warning message you got, you see that it mentions "_size" as the string that is not numeric. Your code snippet will only set $1 to a string of digits, not to the string "_size", right? So, I don't think your code snippet is the problem.

        Regarding the line above: somehow, $self->{_size} is getting set to the string "_size", instead of to a number.

        Can you post more of the code from Spreadsheet/Format.pm? What method is line 225 part of? We'll just have to keep poking around the code until we figure this out.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://44444]
Approved by root
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2018-04-24 04:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?