Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^7: Iterating Through Cell Blocks with Spreadsheet::Read

by Hammer2001 (Novice)
on Oct 08, 2013 at 20:18 UTC ( #1057457=note: print w/ replies, xml ) Need Help??


in reply to Re^6: Iterating Through Cell Blocks with Spreadsheet::Read
in thread Iterating Through Cell Blocks with Spreadsheet::Read

Anomalous, thanks for your response. Adding a line "print Dumper $sheet;" generates error:

print() on unopened filehandle Dumper at ./minitest.pl line 33.
References like:
my $sheet_count = $book->[0]{sheets};
before the loop work, but even though I have:
$sheet = $book->[$sheet_index] or next;
this does not seem to be doing the trick. I have tried many variations with no success. I had know autovivification as Perl magic. Knowing the proper term allows me to read about the full effects of the feature. Thanks for that. Adding:
use warnings; use strict;
up top makes no difference in the result. Thanks, Hammer.


Comment on Re^7: Iterating Through Cell Blocks with Spreadsheet::Read
Select or Download Code
Re^8: Iterating Through Cell Blocks with Spreadsheet::Read
by AnomalousMonk (Abbot) on Oct 08, 2013 at 20:41 UTC

    You need to
        use Data::Dumper;
    in order for the  Dumper function to be accessible in your code; then
        print Dumper $sheet;
    will actually print something. See Data::Dumper. (I tend to like Data::Dump a bit better.)

    ... even though I have:
    $sheet = $book->[$sheet_index] or next;
    this does not seem to be doing the trick.

    But my point remains the same: in order for a statement like
        $name = $sheet{"${_}28"};
    to work, a hash named  %sheet must exist somewhere in your code (somewhere in scope, that is). I.e., there must be a statement something like
        my %sheet = ( ... );
    somewhere. Do you say that such a statement exists?

    Update: The other point to make is that if the  %sheet hash actually does exist, the expressions  $sheet{"F28"} and  $sheet->{"F28"} access two completely different hashes!

      Anomolous, Data::Dumper works nicely (when used correctly). It shows the expected values in the format:
      'F29' => '1',
      though I can make no sense of the order in which it displays contents. I have:
      my %sheet;
      declaration though it's not initialized. Initialization with:
      my %sheet = ();
      doe not make a difference in the result.

      Thanks,

      Hammer.

        And why would an empty has contain something? It wouldn't right, its empty :)

        Further to Anonymonk's point:

        >perl -wMstrict -le "use Data::Dump; ;; my $sheet = { qw(F29 foo G30 bar) }; dd $sheet; ;; my %sheet; ;; print qq{'$sheet->{F29}'}; print qq{'$sheet{G30}'}; " { F29 => "foo", G30 => "bar" } 'foo' Use of uninitialized value $sheet{"G30"} in concatenation (.) or strin +g at -e line 1. ''

        Do you see how the expressions  $sheet->{F29} and  $sheet{G30} access two completely different structures, one of which is empty?

        ... I can make no sense of the order in which it displays contents.

        A hash has no internal "order" except for the pairing of each unique key with its value. Access to and listing of hash keys, values and key/value pairs is (apparently) random. (Update: Don't be mislead by the fact that the order in the dump displayed above matches the order of initialization of the hash reference example: this is entirely adventitious. The dump of a larger hash structure will show greater disorder — but again, a key always cleaves to its value.)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1057457]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (21)
As of 2014-09-23 14:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (223 votes), past polls