Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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/ 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
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/ and see what is happening at line 225?

      Here's the line from
      $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/ What method is line 225 part of? We'll just have to keep poking around the code until we figure this out.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2018-07-16 20:55 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (349 votes). Check out past polls.