• 数组作为hash元素的时候如何push


    #######################################################################
    #   Copyright (C) 2015 All rights reserved.
    #   
    #   文件名称:p.pl
    #   创 建 者:
    #   创建日期:2015年05月11日
    #   描    述:
    #
    #   备    注:
    #
    #########################################################################
    
    use strict;
    use warnings;
    use Time::HiRes;
    # please add your code here!
    my $tmStarted=Time::HiRes::time;
    if (2 != scalar @ARGV)
    {
        &PrintUsage();
        exit 1;
    }
    =pod
        Subroutine(s);
    =cut
    sub PrintUsage
    {
        print STDERR "perl program.pl [IN] ref_file [IN] input_file [OUT] output_file
    ";
    }
    my $line = "";
    my $linecount = 0;
    my %hash = ();
    open FIN, "<$ARGV[0]" or die "can not open inputfile:$!
    ";
    open FOUT, ">$ARGV[1]" or die "can not create outputfile :$!
    ";
    while(defined($line=<FIN>))
    {
        chomp $line;
        my @vec = split /	/, $line;
        my $size = scalar @vec;
        if ($size < 3)
        {
            print STDERR "$line
    ";
        }
        if (not defined($hash{$vec[0]}))
        {
            my @vectemp = ();
            push @vectemp, $vec[2];
            $hash{$vec[0]} = @vectemp;
        }
        else
        {
            push @{$hash{$vec[0]}}, $vec[2];
        }
    
    }
    close FIN;
    foreach my $key (keys%hash)
    {
        my @vec2 = @{$hash{$key}};
        my $size = scalar @vec2;
        my $part = "";
        for (my $i = 0; $i <$size; $i++)
        {
            $part.=$vec2[$i];
            if ($i < $size - 1)
            {
                $part.=",";
            }
        }
        print FOUT "$key	$part
    ";
    }
    close FOUT;
    print STDERR "$0 has finished,congratulations!
    ";
    print STDERR "Time elapsed:".(Time::HiRes::time-$tmStarted)."
    ";
  • 相关阅读:
    webservice的简单介绍
    如何在page_load方法判断是服务器端控件引发的page_load方法
    android架构概述
    页面传递数组参数
    XML与DataTable/DataSet互转
    jquery调用asp.net 页面后台方法
    asp.net缓存机制
    jQuery操作radio,checkbox,select
    jquery选择器
    android开发环境的搭建过程
  • 原文地址:https://www.cnblogs.com/finallyliuyu/p/4495320.html
Copyright © 2020-2023  润新知