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

Perl的Data :: Dumper显示对象而不是值

发布时间:2020-12-15 21:59:45 所属栏目:大数据 来源:网络整理
导读:foreach my $row (1..$end) { foreach my $col (3..27 ) { # skip empty cells next unless defined $worksheet-Cells($row,$col)-{'Value'}; # print out the contents of a cell $var = $worksheet-Cells($row,$col)-{'Value'}; push @dates,$var; print $
foreach my $row (1..$end) 
 { 
  foreach my $col (3..27 ) 
  { 
    # skip empty cells 
    next unless defined 
    $worksheet->Cells($row,$col)->{'Value'}; 

    # print out the contents of a cell  
    $var = $worksheet->Cells($row,$col)->{'Value'};     
    push @dates,$var;  

    print $var; #this prints the value just fine
  } 
 }  

my %hash;
$hash{'first'} = @dates;
print Dumper %hash; #This prints object information

我使用模块OLE for Perl和我从工作表中获得的每个值并打印$var然后我得到了预期的值,但是当我把所有内容放入哈希时它打印:

'first' => [
bless( do{(my $o = 15375916)},'OLE::Variant'),bless( do{(my $o = 15372208)},

等等.我一定不明白哈希的事情,因为我真的很难过.

解决方法

push @dates,$var将OLE :: Variant对象推送到@dates数组,而print $var调用隐式OLE :: Variant方法将对象转换为字符串.

如果你还想让@dates只包含底层字符串值而不是对象本身,比如说

push @dates,"$var";

在将日期对象放入@dates数组之前将其字符串化.

(编辑:李大同)

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

    推荐文章
      热点阅读