Helo all, what I am trying to do is convert a value contained whitin a hash from string to float, but I fail to find the error, this is that I have tried:
$ cat test.pl #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my ($input_string, %job_task); sub sanitize_data{ my $data = shift; $data->{'work_hours'} = (split(/\s+/,$data->{'work_hours'}))[0]; $data->{'work_hours_to_float_try1'} = sprintf("%.2f",$data->{'work_hours'}); $data->{'work_hours_to_float_try2'} = 0 + $data->{'work_hours'}; $data->{'work_hours_to_float_try3'} = 1.1 + 4.1; print Dumper $data; }; $input_string = ' Work Hours: 4.1 hours'; if($input_string =~ /^\s+([^:]+):\s+(.*)/){ my ($k, $v) = ( lc($1), $2 ); $k =~ s/\s/_/g; $job_task{$k}=$v; sanitize_data(\%job_task); }; $ ./test.pl $VAR1 = { 'work_hours_to_float_try3' => '5.2', 'work_hours_to_float_try2' => '4.1', 'work_hours' => '4.1', 'work_hours_to_float_try1' => '4.10' }; why the resulting value is always a string? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/