Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

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


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

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.


Comment on Re^11: Iterating Through Cell Blocks with Spreadsheet::Read
Re^12: Iterating Through Cell Blocks with Spreadsheet::Read
by AnomalousMonk (Abbot) on Oct 09, 2013 at 04:27 UTC
    How can I use a variable instead of "F28"?

    This essentially just goes back to toolic's original reply: make sure that  $sheet is a hash reference and that its content is what you expect; access the contents via  -> arrow notation, forming the hash keys as before with something like  $name = $sheet->{"${_}28"}; etc. (A simple concatenation like  $sheet->{$_ . '28'} would work just as well.)

Re^12: Iterating Through Cell Blocks with Spreadsheet::Read
by Hammer2001 (Novice) on Oct 09, 2013 at 04:38 UTC
    Here's the problem restated another way. Here's a script to read Excel XLSX cell values using Spreadsheet::Read:
    #!/usr/bin/perl -w use warnings; use strict; use Spreadsheet::Read; my $name = ""; my $strain = ""; my $initdensity = ""; my $finaldensity = ""; my $avedensity = ""; my $book; my $sheet; my %sheet = (); $book = ReadData ($inbook); my @x = qw(F G H I J K); for my $sheet_index (1 .. $sheet_count) { $sheet = $book->[$sheet_index] or next; foreach (@x) { $name = $sheet{'F28'}; $strain = $sheet{'F29'}; $initdensity = $sheet{'F30'}; $finaldensity = $sheet{'F31'}; $avedensity = $sheet{'F32'}; print "Found sheet with label: $sheet{label}\n"; print "COL=$_ $name $strain $initdensity $finaldensity $avedens +ity\n"; } }
    I need to after reading keys F28..F32 read G28..G32 through K28..K32. How can I key it on values from array @x?

    Thanks, Hammer

      I'm not at all familiar with Spreadsheet::Read (in fact, I'm not greatly familiar with spreadsheets in general), but the code you show seems close to being workable. Do this:

      • Get rid of the whole
            my %sheet = ();
        statement. In the code you show, it seems to be doing nothing more than confusing the heck out of you.
      • The  foreach (@x) { ... } loop seems OK for looping over the values of the  @x array, with the  $_ default scalar being "topicalized" to each column-name string in turn.
      • Form the cell name as has been discussed and access the cell within the  $sheet hash reference (I'm assuming this is a valid operation) using the  -> arrow operator, e.g.
            $name = $sheet->{"${_}28"};
        or perhaps
            $name = $sheet->{$_ . '28'};
      • Report results. Don't just say "it doesn't work", that's almost useless. Describe your expectations and report how the code fails to meet your expectations. Report exact warning or error messages.
      • Ponder the Basic debugging checklist.

      Good luck.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2015-07-04 03:52 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 (57 votes), past polls