By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,712 Members | 1,958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,712 IT Pros & Developers. It's quick & easy.

Having trouble with Spreadsheet::Read hash

P: 2
Hey everyone. I'm using Spreadsheet::Read to grab data from an excel .xls file and I can't figure out how to loop through the hash and display the data. Using print works but I would like to print column A1 through A100 without having to manual type them all out. I tried a lot of different things so any help would be really appreciated. Here is the code I've got so far:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4. use Spreadsheet::Read;
  5. use Data::Dumper;
  6.  
  7. my $xls = ReadData ("test.xls");
  8.  
  9. print $xls->[1]{'A1'};
  10. print $xls->[1]{'A2'};
  11. print $xls->[1]{'A3'};
  12.  
  13. exit;
Jan 21 '10 #1
Share this Question
Share on Google+
2 Replies


Expert
P: 70
Try this:

Expand|Select|Wrap|Line Numbers
  1. for my $cell (map { "A$_" } 1 .. 100) {
  2.     print $xls->[1]{$cell};
  3. }
  4.  
Jan 21 '10 #2

P: 2
Yessssss, Thank you so much!

I will be sure to come back here if I have any more questions. The if loop helped me figure out how to check if any cells contain the word "test":

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4. use Spreadsheet::Read;
  5. use Data::Dumper;
  6.  
  7. my $xls = ReadData ("test.xls");
  8.  
  9.  
  10. for my $cell (map { "A$_" } 1 .. 100) {
  11. $_ = $xls->[1]{$cell};
  12.  
  13.     if (/test/) {
  14.         print "found \"test\" in cell: $cell\n";
  15.     }
  16. }
  17.  
  18. exit;
Jan 23 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.