Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by AnomalousMonk (Bishop)
on Oct 08, 2013 at 20:41 UTC ( #1057460=note: print w/replies, xml ) Need Help??


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

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!

Replies are listed 'Best First'.
Re^9: Iterating Through Cell Blocks with Spreadsheet::Read
by Hammer2001 (Novice) on Oct 08, 2013 at 21:41 UTC
    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.)

        Yes, of course. Thanks for the clarification, AnomalousMonk. Now it makes. sense.

        My objective, once again, is to access F29 through F32 to K29 through K32, in a routine. I can't figure how to iterate over rows through a variable. It only works for me when hash key is explicit (i.e. $name = $sheet{"F28"};). How can I use a variable instead of "F28"?

        Thanks,

        Hammer.

      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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1057460]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2022-09-29 11:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (125 votes). Check out past polls.

    Notices?