Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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
Replies are listed 'Best First'.
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.

        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.)

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

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 chilling in the Monastery: (14)
As of 2015-07-30 14:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (271 votes), past polls