Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^4: string to number via data dumper

by Laurent_R (Monsignor)
on Sep 28, 2013 at 14:54 UTC ( #1056139=note: print w/ replies, xml ) Need Help??

in reply to Re^3: string to number via data dumper
in thread string to number via data dumper

Ken said it all, but just in case you have trouble understanding his example, just change:

my $n= "$val+8"; print $n;


my $n= $val+8; print $n;

In the first code snippet above, you are constructing a string composed of the concatenation of your value (in string form) and the "+8" string. In other words, you are just doing string manipulation, no arithmetics. The second code snippet is actually adding the number 8 to your value. Now, if you understood the difference, go back to Ken's example.

Comment on Re^4: string to number via data dumper
Select or Download Code
Replies are listed 'Best First'.
Re^5: string to number via data dumper
by semipro (Novice) on Sep 29, 2013 at 09:42 UTC
    Hi merci! I just realized that data dumper is not appropriate to handle numbers. Extracting the numerical part of the string needs some further code to get rid off all non numerical values inside the string such as $Value1:. After that you can treat it numerical. Because of that I desided not to use data dumper. Better solution I found for me:
    #!/usr/bin/perl -w #use strict; my $resultnow='C:/Users/user/Desktop/solution.dat'; open (FILE, '<', $resultnow) or die "$resultnow File not found : $!"; my @lines = <FILE>; my $valuenow= $lines[9]; my @va=split(' ',$valuenow); print $va[3];
    So I am using now split. I guess data dumper is only good for "final" values or direct string output. But not for further data handling. So thank you for the fruitful collaboration. :-) That helped me alot. Best regards

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056139]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2015-11-28 18:20 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (743 votes), past polls