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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.