【问题标题】:Perl multi demonstration hashPerl 多演示哈希
【发布时间】:2014-09-08 12:07:43
【问题描述】:

我怎样才能像这样创建数据并将数据添加到哈希%grade_two

$grade_two{Student}{Subject}{Test}{Score and edited Score} = ();

我不想对数据进行硬编码。我将通过终端<STDIN>or 读取文件流入变量。

{Score and edited Score} 应该有一个或多个条目(数组)if any

我需要使用参考吗?或者我可以不参考? 请给我一个代码示例并解释您的答案。谢谢你。

【问题讨论】:

  • 你能提供一个预期输入流的例子吗?
  • 'Joe Ola''Math''Quiz1''98''ALex R''Math''Quiz1''70''Ashley Brwown''English''Test1''80''复习分数86''Joe Ola''数学''Quiz3' 80'Ashley Brown''英语''中期''95'

标签: arrays perl hash multidimensional-array


【解决方案1】:

使用@{} 表示法“取消引用”对数组的哈希引用。注意 在 perl 文件的顶部使用“use strict”是一种很好的做法,并且会持续很长时间 改进 perl 编码风格的方法:)

试试这样的:

use strict;

my %grade_two;

$grade_two{Student}{Subject}{Test}{'Score and edited Score'} = ();
push(@{$grade_two{Student}{Subject}{Test}{'Score and edited Score'}}, "123");
push(@{$grade_two{Student}{Subject}{Test}{'Score and edited Score'}}, "456");

1;

【讨论】:

    猜你喜欢
    • 2012-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-22
    • 2015-01-17
    • 2013-12-20
    • 2013-08-10
    相关资源
    最近更新 更多