in reply to Consecutive if loops

I added a few comments to your script. I don't exactly know what outcome you want, but I do spot a few things that are most likely errors.

#!/usr/bin/perl -w use strict; use locale; use warnings; use diagnostics; use utf8; binmode(STDIN, ":encoding(utf8)"); # prepend the colon to "encoding" +. binmode(STDOUT, ":encoding(utf8)"); # prepend the colon to "encoding" +. binmode(STDERR, ":encoding(utf8)"); # prepend the colon to "encoding" +. my $data_file = "data.txt"; my ($start, $end); # Warning: this works, but DATA is special. Better to use a different + name. open (DATA, '<:utf8', $data_file) || die "Couldn't open $data_file : $ +!\n"; # Consider using IO::Prompt::Tiny, or IO::Prompt::Hooked. 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>); # Questionable: Are you really intending to pass any input that contai +ns four # contiguous digits? Maybe so, but seems like an inadequate validatio +n. if ($start_input =~ /\d\d\d\d/ && $end_input =~ /\d\d\d\d/){ while (<DATA>){ # Even more questionable: None of your suggested input formats wou +ld match. # Did you mean $start_input =~ /\d{6}/ ? When would the input eve +r have # six contiguous digits? 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/ +){ # Maybe you intended to do this immediately after receiving input. +That would # fix the second "if", but would break the fourth "if" conditional. $start_input =~ tr/\.//d; print "$start_input\n"; $end_input =~ tr/\.//d; print "$end_input\n"; while (<DATA>){ # I don't see this ever working. Did you mean $start_input =~ /\d +{4}/ .. ? 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);

Dave