我在外部文本文件中有如下所示的数据结构。它更大,但格式保持不变。我如何使用此文件来创建我可以使用的perl数据结构。我想我可以做一个文件复制并替换所有:with =>。但接下来要使用这个外部代码一个变量。
好像是my $hashref = FILE;
提前致谢
文件的格式
{
"auto_close" => "true",
"topology" => {
"drawings" => [],
"links" => [
{
"link_id" => "2c1a64c9-a96e-4c94-ac3d-bbaeadde3773",
"nodes" => [
{
"adapter_number" => 2,
"label" => {
"rotation" => 0,
"style" => "font-family =>",
},
"node_id" => "0807cfc6-ffc9-4762-ad11-d021e2e49b0e",
},
{
"adapter_number" => 0,
"label" => {
"rotation" => 0,
"style" => "fill-opacity => 1.0;",
},
"node_id" => "aeab6b0b-6fd3-43d8-a547-7cd2752dc800",
"port_number" => 0
}
]
}
],
"nodes" => [
{
"compute_id" => "local",
"label" => {
"rotation" => 0,
"style" => "font-family => TypeWriter;",
"text" => "East1",
},
"name" => "East1",
"properties" => {
"auto_delete_disks" => "true",
"platform" => "c7200",
"power_supplies" => [
1,
1
],
"sensors" => [
22
],
},
"symbol" => " =>/symbols/router.svg",
"z" => 1
},
]
},
"type" => "topology",
"version" => "2.0.3"
};
答案 0 :(得分:1)
我已经明白了
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use File::Slurp;
my $text=read_file($ARGV[0]);
$text=~s/:/ =>/g;
$text=~s/true/"true"/g;
$text=~s/false/"false"/g;
$text=~s/null/"null"/g;
my $ref= eval $text;