Monks I am seeking your help once again. I apologize in advance if I am just over looking something very simple, but I just can't figure out what I am doing wrong here.
I am working on a script that first reads some data into a hash. Then it reads some data from a flat txt benchmark file into another hash. From there I am printing a report that essentially just compares the hashes to print the data. However I am getting an error that one of my variables needs to an explicit package name and I can;t figure out why. Here is the code. I have tried to strip it down to just the pertinent stuff.
#!/usr/local/bin/perl -w
use strict;
use vars qw($opt_m);
use Getopt::Std;
my ($today) = &finder();
if ($script_mode eq 'normal') {
my ($yesterday) = &read_benchmark();
&write_benchmark();
&print_report();
} else {
&write_benchmark();
}
sub finder {
my %today;
open (IN, "< todays data") or die "$!";
while (<IN>) {
chomp;
$today{$_}++;
}
close (IN);
return \%today;
}
sub read_benchmark {
my %yesterday;
open (BENCH, "< benchmark.txt") or die "$!";
while (<BENCH>) {
chomp;
$yesterday{$_}++;
}
close (BENCH);
return \%yesterday;
}
sub write_benchmark {
open (BENCH, "> benchmark.txt") or die "$!";
foreach (sort keys %$today) {
print BENCH "$_\n";
}
close (BENCH);
chmod(0640, "benchmark.txt") or die "$!";
return;
}
sub print_report {
foreach (sort keys %$today) {
print LOG "$_\n" unless exists $yesterday->{$_};
}
foreach (sort keys %$yesterday) {
print LOG "$_\n" unless exists $today->{$_};
}
print LOG "End of Report.\n";
return;
}
The Error message I get is.
Global symbol "$yesterday" requires explicit package name at ./daily10 line 115.
Line 115 is where I try to use $yesterday->{$_}.
Now I am guessing that %yesterday isn't accessible because it is returned to that if statement, but the other subs that access are within that if statement too. I guess by declaring the variable in
use vars that would probably work, but I don't understand why it isn;t working here. Any help is appreciated. Thanks.