Could someone kindly point me why this snippet is not compiled:
my $crond = "/etc/init.d/crond";
if( -e $crond ) {
my $d = "d";
}
my $crond = "/etc/init.d/cron$d";
Error:
"my" variable $crond masks earlier declaration in same scope at /home/andrew/sandbox/processes2cron.pl line 27.
Global symbol "$d" requires explicit package name at /home/andrew/sandbox/processes2cron.pl line 27.
I tried different variations with ‘my’ but still the scope is defined uncorrectly. Thanks.
It’s just as the error message says. You’re redeclaring
$cronwithin the same scope, and$dis only defined within theifblock, so the compiler expects$dto be a global variable when you use it on the last line, and complains when it can’t find it.