Perl Data :: Dumper shows objects instead of values

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 

I use the OLE module for Perl and every value that I get on my sheet and print $ var, then I get the expected value, but when I put everything in the hash, it prints:

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

And so on. I do not have to understand something about hashes, because I'm really here.

+6
perl hash ole data-dumper
source share
2 answers

push @dates, $var pushes the OLE::Variant object to your @dates array, and print $var calls the implicit OLE::Variant method to convert the object to a string.

If you also want @dates just contain basic string values, not the objects themselves, let's say

 push @dates, "$var"; 

which will pull together the date object before putting it into the @dates array.

+10
source share

The values ​​returned by calling $worksheet->Cells($row,$col)->{'Value'} are objects that are mostly C / C ++ in nature, and Perl only has an object handle represented by a memory cell ( which you see in the dump as a large integer) Many of the CPAN modules that wrap the underlying C / C ++ libraries behave the same (for example, XML :: LibXML, which appears in plain sight). Short answer: this is an object, and that’s all you can see with Data :: Dumper, unfortunately. They are essentially blissful scalar links, and all operations on them go through methods, and not through the actual value of the base link itself.

+3
source share

All Articles