Deb wrote:
>
> I need help understanding why I'm getting this complaint,
>
> Use of uninitialized value in concatenation (.) or string at test.pl line 2.
>
> It says its unitialized, but isn't the my $status initializing the scalar?
> I'm so confused.
>
> Here's the code:
>
>
> #!/usr/local/bin/perl -w
> my $status = `ps -ef | /bin/egrep '/usr/lib/sendmail' | /bin/grep -v grep | awk
> '{print $2}'`;
> print $status;
> if ($status) {
> print "We have sendmail\n";
> } else {
> print "We don't\n";
> }
>
> And the output:
>
> Use of uninitialized value in concatenation (.) or string at test.pl line 2.
> root 19460 1 0 Dec 18 ? 0:08 /usr/lib/sendmail -bd -q15m
> We have sendmail
Hi Deb.
Perl is trying to expand $2 in your string. Since Perl's $2 is undefined it
gives you the warning (full marks for using -w but 'use strict' would help
even more).
Change it to
awk '{print \$2}'
and it should work for you.
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>