Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

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


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

[from Re^2: Iterating Through Cell Blocks with Spreadsheet::Read:]
I still get the same error "Use of uninitialized value in concatenation (.) or string at..." on the print statement after replacing lines like "$name = $sheet{"$_28"}" with "$name = $sheet{"${_}28"}".

I'm assuming the error message quoted from an earlier reply refers to the code most recently posted. In this code, my interpretation of the
    my $sheet = $book->[$sheet_index] or next;
statement is that it creates a hash reference named $sheet. If you dump this variable with something like
    print Dumper $sheet;
is that what you see? If the scalar  $sheet is a hash reference, its elements are accessed like  $sheet->{'string'} (note the  -> operator; see The Arrow Operator in perlop; also see perlref).

After that, statements like
    $name = $sheet{"${_}28"};
assign values of keys of the hash named  %sheet (not the hash reference  $sheet) to variables. Does this hash exist? It is not shown in your posted code, and I don't understand how your code can possibly work if it does not exist. Are you aware of the phenomenon of "autovivification" in Perl?

Do you have warnings and strictures (see warnings and strict) enabled, i.e., do you have statements like
    use warnings;
    use strict;
at or very near the top of each source file? Bugs arising from autovivification direct-versus-referential access confusion can easily bite without warnings and strictures.

Update: On second thought, the reference to autovivification above is misguided, but the hash  %sheet really does have to exist somewhere with meaningful data in it for the posted code to work.

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

      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.

Log In?
Username:
Password:

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

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




    Results (125 votes). Check out past polls.

    Notices?