English 中文(简体)
具有活力的多功能性
原标题:Perl Dynamically Generated Multidimentional Associative Array

这可能是我的简单监督(或比我的技能更先进)。 我正通过阅读档案材料,积极填补一个2个联系阵列。

my @data;
while (<FILE>) {
    chomp;

    my $ID,$COUNT;
    print "READ: " . $_ . "
"; #Debug 1

    ($ID,$COUNT,undef,undef,undef) = split /,/;
    print "DATA: " . $ID . "," . $COUNT . "
"; # Debug 2

    $data{$ID}{"count"} = $COUNT;
    #push @{$data{$ID}{"count"}}, $COUNT; 

              print $data{$ID}{"count"} . "
"; # Debug 3
}

第一个印刷版(图1)将印刷一个类似于313,3的线路。

第二部印刷版(图2)将印刷一条DATA:313,3

第三版(图3)将打印一个空白线。

这个问题似乎在我试图将数据插入联系阵列。 我尝试了直接插入和推进方法,但没有结果。 我在PHP上这样做了,但我认为我正在Perl看到这一点。 我确实看了讲卫生运动的卫生、卫生、体育和体育部的每百页,但我看不出他们有活力的一代人。 任何建议都将是巨大的。

最佳回答

将你的工作方式分派给酒吧。 你不恰当地宣布了你们的变量。 您的联系阵列称作Perl的散列,其序号为% sigil,因此,在排期之前,您应撰写my%data。 在行程中,<条码>my操作者需要按规定申请名单,因此应为<条码>米(ID,$COUNT);。

这一最低实例证明:

use warnings;  # place these lines at the top of all of your programs
use strict;    # they will catch many errors for you

my %data;  # hash variable
while (<DATA>) {
    chomp;
    my ($id, $count) = split /,/;  # simplify the split

    $data{$id}{count} = $count;    # build your hash
}

print "got: $data{des313}{count}
";  # prints "got: 3"

__DATA__
des313,3
问题回答

暂无回答




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签