steph_bow has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks, I am doing some computation on numbers but I get strange results, because the "0" seem to disappear. Have you got some hint ? Thanks a lot !
#! perl -slw use strict; use diagnostics; use Data::Dump qw[ pp ]; my $diff = 15; while (<DATA>){ my $former_time = substr($_, 0, 4); my $former_hour = substr($_, 0, 2); my $former_mn = substr($_, 2, 2); my $new_hour = $former_hour; my $new_mn = $former_mn + $diff ; if ($new_mn >= 60){ $new_mn = $new_mn - 60; $new_hour = $new_hour + 1; } # cas où $diff est suffisamment négatif pour faire basculer dans l +'heure d'avant elsif ($new_mn < 0){ $new_mn = $new_mn + 60; $new_hour = $new_hour - 1; } my $new_time = "$new_hour"."$new_mn"; print STDOUT "former_time is $former_time"; print STDOUT "new time is $new_time"; } __DATA__ 1250 0549 1103 1509 0423 0834
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: problem of configration
by cdarke (Prior) on Nov 27, 2008 at 17:11 UTC | |
|
Re: problem of configration
by oko1 (Deacon) on Nov 28, 2008 at 02:58 UTC | |
|
Re: problem of configration
by eye (Chaplain) on Nov 28, 2008 at 06:59 UTC |