Hello monks

I new to perl and I can't really tell why this code is not working :

#!/usr/bin/perl -w use strict; use locale; use warnings; #use diagnostics; use utf8; binmode(STDIN, "encoding(utf8)"); binmode(STDOUT, "encoding(utf8)"); binmode(STDERR, "encoding(utf8)"); my $data_file = "data.txt"; my ($start, $end); open (DATA, '<:utf8', $data_file) || die "Couldn't open $data_file : $ +!\n"; print "Start time (format : yyyy.mm.dd.hh):\n"; chomp (my $start_input = <STDIN>); print "End time (format : yyyy.mm.dd.hh):\n"; chomp (my $end_input = <STDIN>); if ($start_input =~ /\d\d\d\d/ && $end_input =~ /\d\d\d\d/){ while (<DATA>){ if (/$start_input\d\d\d\d\d\d/ .. /$end_input\d\d\d\d\d\d/){ if ($_ =~ /(.*)\t(.*)\t(.*)/){ print "Date = $1" . "\t" . "Temp_moy_DegCs = $2" . "\ +t" . "HR_moy_s = $3\n"; } } } } if ($start_input =~ /\d\d\d\d\.\d\d/ && $end_input =~ /\d\d\d\d\.\d\d/ +){ $start_input =~ tr/\.//d; print "$start_input\n"; $end_input =~ tr/\.//d; print "$end_input\n"; while (<DATA>){ if (/$start_input\d\d\d\d/ .. /$end_input\d\d\d\d/){ if ($_ =~ /(.*)\t(.*)\t(.*)/){ print "Date = $1" . "\t" . "Temp_moy_DegCs = $2" . "\ +t" . "HR_moy_s = $3\n"; } } } } close (DATA);

When I comment one of the first "if" loops it works just fine for one of the date formats ('yyyy' or 'yyyy.mm'). I also tried using the "elsif", but it's the same thing. Also it still doesn't work by executing all the "if" statments in the same "while" loop.

The source file looks like this

1998032602 -6 77 1998032603 -7 82 1998032604 -7,8 81 1998032605 -8,3 82 1998032606 -8,6 85 1998032607 -2,5 62 1998032608 2,1 37 1998032609 5,5 25 1998032610 8,9 16 1998032611 11 16 1998032612 12,9 15 1998032613 13,3 13 1998032614 13,4 14 1998032615 13,1 16 1999093022 7,2 96 1999093023 5,6 98 1999100100 5,7 99 1999100101 5,9 99 1999100102 5,4 99 1999100103 5,9 99 1999100104 5,9 99 1999100105 5,5 99 1999100106 4,2 99 1999100107 6 99 1999100108 9,3 82 1999100109 12,1 64 1999100110 14,5 50 1999100111 16,5 47 1999100112 17,8 49 1999100113 18,5 49 1999100114 18,6 48

Thank you


In reply to Consecutive if loops by M15U

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.