Problems? Is your data what you think it is? | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
G'day semipro, You really need to show your code (i.e. how you're using the value in a calculation), the output you get as well as any error or warning messages (these need to be exactly as you see them and marked up within <code>...</code> tags). Please read the "How do I post a question effectively?" guidelines for full details regarding this. I suspect the message you're getting is something like:
The part that isn't numeric is:
This is the string that Dumper($items[-1]) would be returning: '-39.99994' is just part of that string. I think you should spend some time reading the Data::Dumper documentation. I suspect you haven't quite understood what it does. A more usual usage would be something like:
There'll be many examples in the monastery (use Super Search). Here's a couple from recent nodes I've written: hashref data structure dump and arrayref data structure dump. Perl will happily convert numbers between string and numeric contexts. For example, this code:
produces this output:
You'll notice that trailing zeros were truncated. You can control the format with sprintf. You can also force the context yourself: 0+$x (numeric); ''.$x (string); !!$x (boolean). -- Ken In reply to Re: string to number via data dumper
by kcott
|
|