Re: Why must I chomp a variable set in a script?



On Jun 18, 8:48 am, numberw...@xxxxxxxxx (Jefferson Kirkland) wrote:

my $emailBody = $prefix . "emailbody";

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?

There's no reason, from what you've told us. chomp() would have no
effect on that variable, as it doesn't end in a newline. My guess is
that either you're leaving out an important detail for the sake of
brevity, or your coworker changed something else too, but mistakenly
believed it was the chomp() that solved the problem.

Can you create a short-but-complete script that demonstrates the
original failure, and then a version that has only the additional
chomp() line inserted but suddenly works correctly?

Also, what is meant by "it doesn't work" in your question? What did
not work? How did it not work? What errors did you receive?

Paul Lalli

.



Relevant Pages

  • Sum not producing zero
    ... Below is a small script and results... ... doing wrong - the sum should produce zero but does not. ...
    (perl.beginners)
  • Re: AIX 5.3 disaster recovery fro AIX newbie
    ... >are you in the server in maint mode? ... I know just because I cannot get in and examined the script it ran. ... one of the scripts smoked /etc/passwd file, to zero. ... If you are not the intended recipient ...
    (AIX-L)
  • Re: problem with a file processing script
    ... but I am far from a script writer, and I recently run into a little ... if the file I am looking for is zero ... the $NEWNUM it's because the extension the third party software is ... print that $EQFILE existed but was empty ...
    (comp.unix.shell)
  • Re: problem with a file processing script
    ... but I am far from a script writer, and I recently run into a little ... if the file I am looking for is zero ... the $NEWNUM it's because the extension the third party software is ... print that $EQFILE existed but was empty ...
    (comp.unix.shell)
  • Re: Why must I chomp a variable set in a script? (Problem Solved)
    ... Why must I chomp a variable set in a script? ... On 6/18/07, Paul Lalli wrote: ... the chomp is no longer in the script as it didn't seem to resolve this ...
    (perl.beginners)