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.