English 中文(简体)
千兆瓦
原标题:Hash of hashes in perl
  • 时间:2010-06-29 15:39:25
  •  标签:
  • perl

我正试图利用这种 has——

#!/usr/bin/perl -w
use strict;

my %hash = ();

sub hash_populate
{
    my $name = "PQR,ABD,XYZ";
    my @parts = split(/,/,$name);
    my $i = $parts[0];
    my $a= $parts[1];
    my $b = $parts[2];

    $hash{$i} = {"A" =>$a,"B" => $b};
    my $c =  $hash{$i}{"A"};
    print $c;
}

我收到表格的错误。

Can t use string ("HASH(0x16c43c)") as a HASH ref while "strict refs" in use

同一代码在<代码>严格使用时不在场。 谁能告诉我为什么?

最佳回答

既然我是在5.8.7年严格地尝试了这一点,而且工作得力,那么我就不得不想到,你实际操作的法典在某种程度上是错误的,而“它没有严格”就是说它确实死了。 只允许你做你想要的东西,让你抓住问题。

因此,答案是

(1) 法典为5.8条(行文法)

2) “无严格工作”是共同声明 在我能够看到一些试图强化散射参考的法典之前,我可以说没有任何不同。

3) 为什么“无严格限制的工作”是你如何适应这一模式的结合,如何理解实际守则,以及“Perl”会允许你在无数次的时间里用严格的折射,而你有时会认为它奏效。

4) 部分工作实际上没有严格限制,而是打算从事。 这正在改变严格的限制(,无严格参照;)是你有意进行地步运行的方式。

问题回答

暂无回答




相关问题
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 ...

热门标签