Having trouble with Spreadsheet::Read hash

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • testingPerl
    New Member
    • Jan 2010
    • 2

    Having trouble with Spreadsheet::Read hash

    Hey everyone. I'm using Spreadsheet::Re ad 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:

    Code:
    #!/usr/bin/perl -w
    
    use strict;
    use Spreadsheet::Read;
    use Data::Dumper;
    
    my $xls = ReadData ("test.xls");
    
    print $xls->[1]{'A1'};
    print $xls->[1]{'A2'};
    print $xls->[1]{'A3'};
    
    exit;
  • toolic
    Recognized Expert New Member
    • Sep 2009
    • 70

    #2
    Try this:

    Code:
    for my $cell (map { "A$_" } 1 .. 100) {
        print $xls->[1]{$cell};
    }

    Comment

    • testingPerl
      New Member
      • Jan 2010
      • 2

      #3
      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":

      Code:
      #!/usr/bin/perl -w
      
      use strict;
      use Spreadsheet::Read;
      use Data::Dumper;
      
      my $xls = ReadData ("test.xls");
      
      
      for my $cell (map { "A$_" } 1 .. 100) {
      $_ = $xls->[1]{$cell};
      
      	if (/test/) {
      		print "found \"test\" in cell: $cell\n";
      	}
      }
      
      exit;

      Comment

      Working...