Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Problem Declaring Variable

by ChOas (Curate)
on Mar 13, 2002 at 16:07 UTC ( #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/;


Comment on Re: Problem Declaring Variable
Download Code
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
Node Status?
node history
Node Type: note [id://151418]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-11-23 07:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (129 votes), past polls