使用散列哈希来编写perl代码

时间:2014-07-28 12:19:36

标签: arrays perl file hash

我是perl的新手。 我有一个形成和使用散列哈希的问题。 任何人都可以指导我解决下面的问题吗?我想知道我的代码中哈希散列的用法,或任何相关的代码也没关系。

问题陈述:

我希望perl代码的输出应该像下面的

Month Date1 year :
hour1: float_max: ?? and NL_max: ??
hour2: float_max: ?? and NL_max: ??
hour.......

month Date2 year :
hour1: float_max: ?? and NL_max: ??
hour2: float_max: ?? and NL_max: ??
hour3.......

根据日期和小时,我想要输出。

这是我写的代码:

our %HoH;
our %table2;
our %table3;

use List::Util qw(min max);
 foreach $line (<DATA>) 
{
    chomp;
    our ($var1,$var2,$date,$time,$var3,$var4,$fl,$var5,$nl) = split(' ',$line);
    our ($val1,$val2,$val3) = split(':', $time);

    $HoH{$date} = [] unless exists $HoH {$date};
    push @{$HoH{$date}}, $val1;

    $table2{$val1} = [] unless exists $table2 {$val1};
    push @{$table2{$val1}}, $fl;



}

foreach $date (sort keys %HoH) 
{
        print "$var2 $date:\n";
        our @date_list = @{$HoH{$date}};
        print join "\n",sort @date_list;
        print "\n";
}
print "\n";
__DATA__
Wed Jul 23 09:24:41 2014 float  61 NL  93
Wed Jul 23 09:24:57 2014 float  61 NL  93
Wed Jul 23 11:24:59 2014 float  61 NL  93
Wed Jul 23 12:25:01 2014 float  61 NL  93
Wed Jul 23 13:25:03 2014 float  61 NL  93
Thu Jul 24 03:06:02 2014 float  0 NL  12
Thu Jul 24 04:08:02 2014 float  0 NL  12
Thu Jul 24 06:10:02 2014 float  0 NL  12
Thu Jul 24 04:12:02 2014 float  0 NL  12
Thu Jul 24 02:14:02 2014 float  0 NL  12
Fri Jul 25 00:00:02 2014 float  4 NL  15
Fri Jul 25 01:02:02 2014 float  4 NL  15
Fri Jul 25 02:04:02 2014 float  4 NL  15
Fri Jul 25 03:06:02 2014 float  4 NL  15
Fri Jul 25 04:08:02 2014 float  4 NL  15
Sat Jul 26 00:00:02 2014 float  1 NL  8
Sat Jul 26 01:02:02 2014 float  2 NL  8
Sat Jul 26 02:04:02 2014 float  2 NL  8
Sat Jul 26 03:06:01 2014 float  2 NL  8
Sat Jul 26 04:08:01 2014 float  2 NL  8
Sun Jul 27 00:00:01 2014 float  0 NL  6
Sun Jul 27 01:02:01 2014 float  0 NL  6
Sun Jul 27 02:04:02 2014 float  0 NL  6
Sun Jul 27 03:06:02 2014 float  0 NL  6
Sun Jul 27 04:08:02 2014 float  0 NL  6

0 个答案:

没有答案