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

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


&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.


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>


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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2015-03-02 13:51 GMT
Find Nodes?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:

    Results (43 votes), past polls