perl 结构$farther ={name,shiduan,age,55};$son ={name,xiaohui,age,25};$farther->{'children'}=[$son];$daughter ={name,xiaoli,age,27};push (@{$farther->{'children'}},$daugther);print $farther->{children}->[1]->{name};怎么显示不出来想要的值
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 08:27:32
perl 结构$farther ={name,shiduan,age,55};$son ={name,xiaohui,age,25};$farther->{'children'}=[$son];$daughter ={name,xiaoli,age,27};push (@{$farther->{'children'}},$daugther);print $farther->{children}->[1]->{name};怎么显示不出来想要的值
perl 结构
$farther ={name,shiduan,age,55};
$son ={name,xiaohui,age,25};
$farther->{'children'}=[$son];
$daughter ={name,xiaoli,age,27};
push (@{$farther->{'children'}},$daugther);
print $farther->{children}->[1]->{name};
怎么显示不出来想要的值啊.指点下, push那里好像有点问题,又不知怎么解决;
perl 结构$farther ={name,shiduan,age,55};$son ={name,xiaohui,age,25};$farther->{'children'}=[$son];$daughter ={name,xiaoli,age,27};push (@{$farther->{'children'}},$daugther);print $farther->{children}->[1]->{name};怎么显示不出来想要的值
更好的写法是:
$farther ={"name","shiduan","age",55};
$son ={"name","xiaohui","age",25};
$farther->{children}=[$son];
$daughter ={"name","xiaoli","age",27};
push (@{$farther->{children}},$daughter);
print $farther->{children}->[1]->{name};
查看详情具体的说明
perl -w file.pl
显示问题!
Unquoted string "name" may clash with future reserved word at d line 1.
Unquoted string "shiduan" may clash with future reserved word at d line 1.
Unquoted string "age" may clash with future reserved word at d line 1.
Unquoted string "name" may clash with future reserved word at d line 2.
Unquoted string "xiaohui" may clash with future reserved word at d line 2.
Unquoted string "age" may clash with future reserved word at d line 2.
Unquoted string "name" may clash with future reserved word at d line 4.
Unquoted string "xiaoli" may clash with future reserved word at d line 4.
Unquoted string "age" may clash with future reserved word at d line 4.
显示有点问题,应该注意的!
Name "main::daugther" used only once: possible typo at d line 5.
Name "main::daughter" used only once: possible typo at d line 4.
Use of uninitialized value in print at d line 6.
暗示你的问题,错误的地方
===>
push (@{$farther->{'children'}},$daugther);
您可以重新写
push (@{$farther->{'children'}},$daughter);