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.#!/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; }
In reply to Problem Declaring Variable by PrimeLord
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |