Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Problem Declaring Variable

by ChOas (Curate)
on Mar 13, 2002 at 16:07 UTC ( [id://151418]=note: print w/replies, xml ) Need Help??


in reply to Problem Declaring Variable

Try:
&print_report($yesterday); #And in print_report: sub print_report { my $yesterday=shift foreach (sort keys %$today) { print LOG "$_\n" unless exists $yesterday->{$_}; } # etc. etc. etc.


GreetZ!,
    ChOas

print "profeth still\n" if /bird|devil/;

Replies are listed 'Best First'.
Re(2): Problem Declaring Variable
by dmmiller2k (Chaplain) on Mar 13, 2002 at 17:21 UTC

    Exactly! ++ChOas.

    Rather than effectively creating a global variable by moving the declaration of my $yesterday out of the if ($script_mode eq 'normal') { statement in the main code (as has been suggested in other comments), it is much better to pass it as a parameter to the print_report subroutine.

    In fact, I'd even take it one step further by also passing $today to all three subroutines that use it (read_benchmark, write_benchmark AND print_report), thus decoupling those subroutines from this specific application and making them candidates for a Perl module (e.g., if the scope of the program were to grow, as occasionally happens, requiring the writing of other scripts which would otherwise have to use cut'n'pasted copies of the same routines)./P>

    dmm

    If you GIVE a man a fish you feed him for a day
    But,
    TEACH him to fish and you feed him for a lifetime

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://151418]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-16 08:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found