Very nice, you've got them all scoped as lexicals. None of the following is criticism, you've chosen a style which is very good for maintainance.

There are a few things you could do to limit scopes further. The simplest and least obtrusive would be a bare block around my $yesterday' and my @msg; like this:

use LWP::UserAgent; { print "\n Fetching log...\n\n"; my $yesterday = Yesterday(); my @msg = Main( 'joe@modem.com', # remote domain 'yosef', # remote id 'secret', # remote password "access.log.$yesterday", # remote logfile input 'c:/logs', # local dir to write to 'access.log', # local logfile output ); print "$_\n" for(@msg); }
I included the initial print statement in the block, just in case you want to localize $\ and kin.

My own inclination is to do away with named variables as much as is consistent with maintainability and readability, so I might have written that as:

{ local $\="\n"; print "\n Fetching log...\n"; print for Main( 'joe@modem.com', # remote domain 'yosef', # remote id 'secret', # remote password "access.log.".Yesterday(), # remote logfile input 'c:/logs', # local dir to write to 'access.log', # local logfile output ); }
but that is less useful for debugging. Its readability is a matter of what one's used to. Similarly, I might write Yesterday() as:
sub Yesterday { sprintf "%04d-%02d-%02d", Add_Delta_Days(Today(),-1); }
If you want to really gild the lily, you could define a private namespace for your sub names: package myscript; sub Main{} sub Yesterday {} package main;. That would be really fussy though ;-)

After Compline,
Zaxo


In reply to Re: Is this a good approach for reducing number of global variables? by Zaxo
in thread Is this a good approach for reducing number of global variables? by ybiC

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.