Hello everyone!  I would really appreciate it if someone could shed some
light on this situation for me.

I have a script that I am writing that looks on a server to see if there are
files in certain directories.  When files are found in a directory, the
script sends an email to the appropriate distribution list for that
directory to let people know files are available.

In the script I have a variable that contains the name of the file that will
hold the body of the email. ( I have to do this because there is an internal
program that sends the email, but that is not in question here.)  The
variable is set like this:

   my $emailBody = $prefix . "emailbody";

where $prefix is a variable set to part of the directory name and it has
"emailbody" concatenated on to it.  So, when the variable is constructed, it
will have the format:

   directoryemailbody

After creating the variable, the script then checks to see if the file
exists from the previous run and deletes it then touches it and opens a file
handle to enable it to be written to.  This part works absolutely perfectly,
with no issues.

The problem is when I get down to the part after the emailbody files are
populated ( they are only populated if files exist) that checks to see if
the files are of zero size.  If they are of zero size, it is supposed to put
a message into the log file saying there are no files for that directory.
If they have size (which means they have a message for the distribution
list, it is supposed to trigger the email program to notify the users.  Here
is the code that wasn't working:

   if(-z $emailBody)
   {
       print LOGFILE ("No files found in $dir \n");
   }
   else
   {
       print LOGFILE ("Files found in $dir.  Sending email to distribution
list. \n");

       $subject = "Files To Retrieve In Directory: $dir \n";
       $recipients = $prefix . "Emails.txt";

       `email program trigger`;
   }

I know that I said "wasn't" in my last statement.  One of my colleagues
discovered that if he puts a "chomp($emailBody);" right before this
statement that it seems to work just fine instead of failing.   Now, as I
mentioned the code before this that checks if the file exists, using THE
SAME variable works fine.  Why would I now, at this point, only a dozen
lines later, have to "chomp" the variable to get this to work?  It isn't
like the value was supplied from the command line, it is set in the script.
Granted, it is inside of a foreach loop that is cycling through the
different directories and setting the variable per the directory, but it is
all done in the script.

Does anyone have any idea why this would have to be chomped at this stage of
the script?

Thank you in advance for your responses!!

Regards,

Jeff Kirkland

Reply via email to