Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Variable Scope Issue?

by insensate (Hermit)
on Apr 19, 2002 at 19:13 UTC ( #160644=perlquestion: print w/replies, xml ) Need Help??
insensate has asked for the wisdom of the Perl Monks concerning the following question:

Greetings. Once again I humbly request your wisdom. I have a script that is called by a cron that has executed flawlessly for several weeks. Today it did not and exited with the ubiqitous "Global symbol requires explicit package name" error. Below is the code in question and the error. I had to remove some specifics from the code for confidentiality reasons.
#!/usr/local/bin/perl $|=1; use strict; use File::Basename; use File::Copy; use File::Find; use File::stat; use Getopt::Long; use POSIX qw(strftime); my $pid1; my $pid2; my $pid3; ######################## my @cmd; my $HOME = "/usr/local/SCRIPTS"; if (!defined ($pid1 = fork)) { die "Unable to fork: $!\n"; } elsif (! $pid1) { # this is the branch for the child process my $cmd1 = "$HOME/"; my $out1 = `$cmd1`; exit; } else{ if (!defined ($pid2 = fork)) { die "Unable to fork: $!\n"; } elsif (! $pid2) { # this is the branch for the child process my $cmd2 = "$HOME/"; my $out2 = `$cmd2`; exit; } waitpid($pid1,0); } waitpid($pid2,0); open(LOGFILE,"../LOGS/temp_file_formyscript.txt"); my $flag = 0; my $file1Flag = 0; my $file2Flag = 0; my $logfile1 = ""; my $logfile2 = ""; while(<LOGFILE>) { chomp; if($flag == 0) { $logfile1 = $_; $flag = 1; } if($flag == 1) { $logfile2 = $_; } } open(LOGFILE1,"../LOGS/oldlogs/$logfile1") ; open(LOGFILE2,"../LOGS/oldlogs/$logfile2") ; while(<LOGFILE1>) { chomp; if ($_ =~ /Successfully Completed/i) { $file1Flag = 1; } } while(<LOGFILE2>) { chomp; if ($_ =~ /Successfully Completed/i) { $file2Flag = 1; } } close LOGFILE; close LOGFILE1; close LOGFILE2; if ( ($file1Flag == 1) and ($file2Flag == 1)) { my $cmd3 = "$HOME/"; my $out3 = `$cmd3`; my $cmd4 = "rm ../LOGS/temp_file_formyscript.txt"; my $out4 = `$cmd4`; # print "inside!!\n"; } else { my $msg = "OPEN_FEED_FAILED\n"; my $cmd5 = "mailx \-s \"OPENFEED\" mypager\ \< err_m +sg.txt "; my $out5 = `$cmd5`; } exit;
Here is today's error:
Global symbol "$cmd3" requires explicit package name at myscript line +88. Execution of myscript aborted due to compilation errors.
Looking at the code this shouldn't happen, I don't know if perhaps a piece of the script was edited this morning then changed back...but a perl -c seems to check out fine...any insight would be greatly appreciated. Jason

Replies are listed 'Best First'.
Re: Variable Scope Issue?
by Biker (Priest) on Apr 19, 2002 at 19:30 UTC

    I cut & pasted your code in a text editor to find the famous line 88, but line 88 is a blank line.

    So you tell us that you have cut out some parts of the script. That makes it very difficult to make use of the error message you supplied.

    So you say that this may not even be the script generating the error message. ("May have been edited again.")

    You know, you really don't provide a lot to go on. I gave it a quick look but didn't immediately find any problem. (I may have missed it.) I stopped looking when I started to think of what you're really asking for:

    "This script is not the one that gave the error, can you help me to find the error?"

    Everything went worng, just as foreseen.

      88 is, in fact, blank. I didn't cut anything from the script, just omitted/generalized pager numbers and script directory names...Given that line 88 is blank can i assume that this code did not produce this error? Thanks!
Re: Variable Scope Issue?
by JayBonci (Curate) on Apr 19, 2002 at 20:49 UTC
    I could be wrong, but is your failing, and the perl error message just bogus? Try changing the $cmd3 to be
    "/bin/sh $HOME/"
    ... and then try the backtick execution of the script. Also, what does the shell script put out when you execute it by itself? If the syntax looks correct, check the dependancies. Do you get any additional info by using #!/usr/local/bin/perl -w?

Re: Variable Scope Issue?
by RMGir (Prior) on Apr 19, 2002 at 20:46 UTC
    I don't see how $cmd3 can generate that error with this script.

    Therefore, I wonder if this is not the script that had the problem. Is that possible?

    If the "myscript" that cron ran isn't THIS myscript, it could explain the issue...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://160644]
Approved by jlk
[GrandFather]: It's a good day end here Corion. The start was somewhat less than average!
[Corion]: GrandFather: All's well that ends well? ;)
[GrandFather]: I'm fighting with a third party device our software is to support. The documentation for the device's SDK is quite a lot less than average and most of today was spent ...
[GrandFather]: discovering that one of the sensors for the device lies about the gain range it is using!
[GrandFather]: However, by the end of the day I had discovered its deceptions and now have it working correctly, so yes, all's well that ends well. :-D
[Corion]: GrandFather: Ah, (hardware) APIs - I have a similar situation with Chrome and its API... It is fairly underdocumented and I guess I have to hunt...
[Corion]: ... down supposedly working code to find out what I'm supposed to do
[GrandFather]: I haven't any "working code" to inspect! I have to find ways to generate reference signals then check the numbers I get at the far end match.

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2017-08-24 07:08 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (365 votes). Check out past polls.