I'm trying to convert over from yrs of not bothering to use `my var;' for variables in my scripts (All are less than 300 lines)
It seems to be a big pita for the most part with no real gain. Given the brief and simple nature of my scripting needs. But that is probably due to developing a sloppy style. I'm not wanting to start a discussion about the value of using `my' here, just looking for some advice on its use. With a script that searches out specific regex from files that may be buried in a complex tree, I want to print the hits of course but also want to keep up with the filenames and directories searched. (only the unique directories). I'm not finding a simple and reliable way to use `my' in keeping with the general reasons to do so. My usage below is not in line with what is advocated here about using `my' and I'd like for it to get closer to that goal. There is a lot of declaring in main that should be more localized. So I'm looking for pointers about how to correct it. I've declared `my %data;' in main because the uniqifyer code inside `wanted()' fails if declared inside `wanted()' and a directory path for each file found gets collected so repeated collection of same path occurs. How do I get around that? I've declared [EMAIL PROTECTED]' in main because I want to use it in `report()'. So trying to keep this as simple as I can, the code runs something along this line: #!/usr/bin/perl -w use strict; use warnings; use File::Find; [...] too many lines of code, including a getopts section, setting up search parameters, tests etc. go here my $SrchTree = shift; find(\&wanted, $SrchTree); my (%data, @SearchedDir); sub wanted { ## Collect only uniq paths if ($data{$File::Find::dir}++ == 0) { ## Make an array of all (Unique) directories searched push @SearchedDir, $File::Find::dir . "\n"; } [...] Too many more lines of processing that gather the lines matching regex and the matching filename (printed as we go) go here. } # Now print a summary print report(); (Note: All vars but `ShowStr' below, were declared in main so they could be used here) sub report { ## Return how many hits.. how many files searched, where ## and the regex used. my $ShowStr = "============================================= <$HitCnt> hits found in <$GlobalCnt> files Using directorie[s]: @SearchedDir Regex used: <$ShowInFileRe> Filename filter: <$FnameFilter> =============================================\n"; return $ShowStr; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/