[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] Module refuses to return a value



I've written my very first Perl module to simplify some of my Excel
tasks (don't ask.  No, really) .

My module looks something like this:

package ExcelUtil;

use strict;
use vars qw($VERSION);
$VERSION='0.5';

sub getCellByValue {
 my ($sheet,$rangeName,$value) = @_;

 ## if the range name ends in :, then select the whole row!
 ## yes, I made this up myself
 if ($rangeName=~m/(\d+):$/) {
   my $row = $1;
   $rangeName = "A$row:AG$row";
 }

 my $range = $sheet->Range($rangeName);

 foreach my $cell (in $range) {
   if ($cell->{'Text'} eq $value) {
     print $cell->{"Text"}."\n";
     return $cell;
   }
 }
 return 0;
}

1;

The print statement is there to tell us the value before it's returned.

I'm calling is like this:

my $cell = ExcelUtil::getCellByValue($Sheet,"A2:A32",$cellDate);
print $cell->{'Text'}."\n";

And this is my output:

12/04/2006
Use of uninitialized value in concatenation (.) or string at tfireport.pls line
182.

12/04/2006 is the correct value that I'm looking for, so the
subroutine is finding the right value, but stubbornly refuses to give
me a value back.

If I put the getCellByValue sub in my script than everything is fine.
So I'm missing something in my module.  Anyone wish to bring me to
enlightenment?


--
Mike Hostetler
http://mike.hostetlerhome.com/