加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Perl Data:Dumper和Storable的用法

发布时间:2020-12-15 23:53:40 所属栏目:大数据 来源:网络整理
导读:1、Data::Dumper 给定一个标量、数组、哈希或引用作为参数,将以PERL语法的方式返回这个数据的内容。 ? 复制代码 代码如下: #!/usr/bin/perl -w use Data::Dumper; use Storable; my $a = "good"; my @myarray = ("hello","world","123",4.5); my %myhash =

1、Data::Dumper
给定一个标量、数组、哈希或引用作为参数,将以PERL语法的方式返回这个数据的内容。
?

复制代码代码如下:

#!/usr/bin/perl -w
use Data::Dumper;
use Storable;

my $a = "good";
my @myarray = ("hello","world","123",4.5);
my %myhash = ( "foo" => 35,
"bar" => 12.4,
?"2.5"=> "hello",
"wilma" => 1.72e30,
"betty" => "bye/n");

print Dumper($a) ."n"x2;
print Dumper(@myarray) ."n"x2;
print Dumper(%myhash) ."n"x2;
print Dumper((%myhash,@myarray)) ."n"x2;

运行结果如下:
$VAR1 = 'good';

$VAR1 = [
? 'hello',
? 'world',
? '123',
? '4.5'
];

$VAR1 = {
? 'betty' => 'bye/n',
? 'bar' => '12.4',
? 'wilma' => '1.72e+30',
? 'foo' => 35,
? '2.5' => 'hello'
};

? '2.5' => 'hello'
};
$VAR2 = [
? 'hello',255)"> 2、Storable
结合Data::Dumper和Storable存储和重新获取数据。你可以用U盘将数据拷走,再在其他服务器上展开。
?

复制代码代码如下:
?? "bar" => 12.4,
?? "2.5"=> "hello",
?? "wilma" => 1.72e30,
?? "betty" => "bye/n");

print Dumper($a) ."n"x2;

print Dumper(@myarray) ."n"x2;

print Dumper(%myhash) ."n"x2;

print Dumper((%myhash,@myarray)) ."n"x2;

###use Storable
print "nmethod 1,use Storable retrieve data:n";
store %myhash,'./file.txt'; #保存数据
my $hashref=retrieve('./file.txt');?#重新获取数据

print Dumper(%$hashref);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读