【问题标题】:initialise list with every element is a an associative array and last elment of the associative array is two d array in perl?每个元素的初始化列表都是一个关联数组,关联数组的最后一个元素是perl中的两个d数组?
【发布时间】:2012-11-05 13:49:20
【问题描述】:

我正在尝试创建一个数据库。列表中的每个元素都包含关联数组形式的详细信息,每个关联数组的最后一个元素都是二维数组,我需要帮助初始化它..

【问题讨论】:

  • 也许您应该提供一些示例输入。还有一些示例代码。
  • 你读过关于自动复活的文章吗?

标签: arrays perl list matrix associative


【解决方案1】:

您需要详细说明您正在尝试做什么,但这可能会有所帮助:它以您描述的方式初始化 Perl 数据结构。请注意,哈希不能有“最后一个”元素(比“关联数组”更好的名称),因为哈希是无序的。我已经使用了数据的customers字段来保存你所说的二维数组。

use strict;
use warnings;

my @list = (
  {
    id => 1,
    name => 'cattle',
    customers => [
      [ 'World Bank', 'Space Marines', 'Undersea Exploration' ],
      [ 1, 2, 3 ],
      [ 0.0500, 0.6322, 0.9930 ],
    ],
  },
  {
    id => 2,
    name => 'arable',
    customers => [
      [ 'Jack Spratt', 'Molly Malone', 'The Whistler' ],
      [ 4, 5, 6 ],
      [ 0.0022, 0.1130, 0.6930 ],
    ],
  },
  {
    id => 3,
    name => 'seafood',
    customers => [
      [ 'Tai Chi School of Fishery', 'Latin Intermediary College', 'Ping Pong Gymnastics' ],
      [ 7, 8, 9 ],
      [ 0.0012, 0.8540, 0.9817 ],
    ],      
  },
);

【讨论】:

  • 感谢您的关注,对不起,我忘了提及我正在尝试从用户本身获取输入,我无法理解如何正确地将分组数据附加到列表中并执行删除或对其进行插入操作..
猜你喜欢
  • 2011-09-02
  • 1970-01-01
  • 2011-10-05
  • 2022-12-07
  • 2012-04-10
  • 2015-08-15
  • 1970-01-01
  • 2019-04-08
  • 1970-01-01
相关资源
最近更新 更多