Perl error: Can't call method "value" on an undefined value

Hi,

I am running a perl script to automate a process and I keep running into a error can't find the "value"

Can't call method "value" on an undefined value at process_file.pl line 44.
file is CVS
cell is ifdfdxrfmp.ksh

Here is the script I have also attached it as well:

#################################
#    process_file.pl        #         
#################################

#!/user/bin/perl -w

use strict;
use Spreadsheet::ParseExcel;
use Net::SMTP;

#Parse excel file
#Replace Perl_test.xls with the excel filename
my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse("Perl_test.xls");

#Get tag from excel cell N9
my $worksheet = $workbook->worksheet('Scripts');
my $tagcell = $worksheet->get_cell(8, 13);
my $tag = $tagcell->value();

#Get checkout dir from excell cell O9
my $dircell = $worksheet->get_cell(8, 14);
my $dir = $dircell->value();

system("date +%m/%d/%Y' '%T >> process_file_log"); 
system("echo the tag is $tag >> process_file_log");
system("echo the checkout dir is $dir >> process_file_log");

#If checkout dir starts with "/", then abort and send email with error
if ($dir =~ /^\//) {
    system("echo 'Error: The checkout dir starts with /' > error_log");
}
else {
    #Run CVS check out command
    system ("echo Checking out files from CVS ... >> process_file_log");
    system("cvs co -r $tag $dir >> process_file_log");
    
    #Compare files with the files listed from cell L9 to L58
    foreach my $file (glob("$dir/*")) {
        $file =~s/.*\///;
        print "file is $file\n";
        foreach my $row (8..57) {
            my $fcell = $worksheet->get_cell($row, 11);
            my $name = $fcell->value();
            print "cell is $name\n";
            
            #If file name is the same
            if ($file eq $name) {
                my $targetcell = $worksheet->get_cell($row, 15);
                my $target = $targetcell->value();
                print "target dir is $target\n";
                system("mkdir -p $target");

                #If file with same name already exists
                foreach my $f (glob("$target/*")) {
                    $f =~ s/.*\///;    
                    if ($f eq $file) {
                        print "$f already exists \n";
                        #Current date and time
                        my ($sec, $min, $hour, $mday, $mon, $year) = localtime(time);
                        $mon  += 1;
                        $year += 1900;
                        my $time = (sprintf "%02d%02d", $hour, $min);
                        my $date = $year.$mon.$mday.$time;
                        my $new = $f.".B".$date;
                        system("echo $f already exists >> process_file_log");                        
                        system("echo Renaming $f to $new >> process_file_log");
                        system("mv $target/$f $target/$new");
                        last;
                    }
                }
                
                #Copy checked out file to target dir
                system("echo Copying $file to $target/ >> process_file_log");
                system("cp $dir/$file $target/");
                                                    
                #If file ends with .ksh, .sh or .pl
                #Then chmod 750
                system("echo Changing the permission of $file >> process_file_log");
                if ($file =~ /\.ksh/) {
                    system("chmod 750 $target/$file");
                }
                elsif ($file =~ /\.sh/) {
                    system("chmod 750 $target/$file");
                }
                elsif ($file =~ /\.PL/) {
                    system("chmod 750 $target/$file");
                }
                #Else chmod 660
                else {
                    system("chmod 660 $target/$file");
                }
                #Assign owner and group        
                system("echo Changing the owner and group of $file >> process_file_log");        
                system("chown ifstech $target/$file");
                system("chgrp support $target/$file");
                
            }
        }
    }
}
system("echo '==============================================================================>' >> process_file_log");

#Send email if there is an error
open( my $error, "<error_log");
my @log = <$error>;
if (scalar(@log) == 0) {
    close $error;
}
else {
    #Define the mail settings here
    my $mailhost = '10.201.40.28'; 
    my $sender = 'sender@domain.com';
    my $recipient = 'receiver@domain.com';
    
    my $smtp = Net::SMTP->new("$mailhost");
    
    #Mail header and body    
    my $subject = 'Error message';
    $smtp->mail("$sender");
    $smtp->to($recipient);
    $smtp->data();
    $smtp->datasend("To: $recipient \n");
    $smtp->datasend("From: $sender \n");
    $smtp->datasend("Subject: $subject \n" );
    $smtp->datasend("\n");
    $smtp->datasend("@log");
    $smtp->datasend("\n");
    $smtp->dataend();
    $smtp->quit;

    close $error;
}




It's supposed to find a files within the checked out dir and then compare it to the excel spreadsheet. it finds the folder "CVS" but not the file.

also to add. I have removed my personal info in the email section but that does not seem to work as well when i input the data. we have some older scripts where we do not specify the smtp host and the ip we only specify the email address. is this at all possible in this script to?

            my $fcell = $worksheet->get_cell($row, 11);
            my $name = $fcell->value();

What's probably happened is that get_cell() returned an undefined object (perhaps because that cell was undefined or empty), and thus, $fcell->value() doesn't have any meaning. Test $fcell before trying to use it:

            next unless $fcell;

As to your 2nd question:

That depends on your email set up. On most UNIX systems you can send the mail via sendmail directly, but it's not portable to, say, windows systems:

open(SMTP,"|/usr/lib/sendmail -t");
print SMTP "From: $sender\n";
print SMTP "To: $recipient\n";
print SMTP "Subject: $subject\n";
print SMTP "\n";
print SMTP join("\n",@log);
print SMTP "\n";
close SMTP;