PrimeLord has asked for the wisdom of the Perl Monks concerning the following question:
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem Declaring Variable
by ChOas (Curate) on Mar 13, 2002 at 16:07 UTC | |
by dmmiller2k (Chaplain) on Mar 13, 2002 at 17:21 UTC | |
|
Re: Problem Declaring Variable
by dragonchild (Archbishop) on Mar 13, 2002 at 16:13 UTC | |
by derby (Abbot) on Mar 13, 2002 at 16:19 UTC | |
by Juerd (Abbot) on Mar 13, 2002 at 16:46 UTC | |
by Juerd (Abbot) on Mar 13, 2002 at 16:49 UTC | |
|
Re: Problem Declaring Variable
by YuckFoo (Abbot) on Mar 13, 2002 at 16:19 UTC | |
|
Re: Problem Declaring Variable
by PrimeLord (Pilgrim) on Mar 13, 2002 at 16:22 UTC |