in reply to Re: Re: Re: Permissions Utility Script for sysadmins - seeking comments
in thread Permissions Utility Script for sysadmins - seeking comments
sub wanted_c { if ((-d $_) && ($d_mode) { change_mode($_, $d_mode); $d_mode = ""; wanted_c(); } elsif ((-d $_) && ($d_own)) { change_owner($_, $d_own); $d_own = ""; wanted_c(); }
That way it gets called as many times as is applicable to the file. Thanks for the pointer - I look forward to looking into your hash idea, which is slightly coalescing in my brain, but wouldn't mind your nudging it a bit with some advice/examples.
-Shane UPDATE: This fixed the problem but created another - it is doing everything, but only on one file! I see it is because of setting the variables to "", but am kinda unsure of what to do instead...
2nd UPDATE: Things are good now except for one thing, in order to fix the problem I created
my %info = %{ $config{$test}{$tester} };
after the spot you suggest a hash. I then put
else { while(my($key,$val) = each(%info)) { if ($key eq "dir-mode") { $d_mode = $val} elsif ($key eq "file-mode") { $f_mode = $val} elsif ($key eq "link-mode") { $l_mode = $val} elsif ($key eq "dir-owner") { $d_own = $val} elsif ($key eq "file-owner") { $f_own = $val} elsif ($key eq "link-owner") { $l_own = $val} elsif ($key eq "dir-group") { $d_grp = $val} elsif ($key eq "file-group") { $f_grp = $val} elsif ($key eq "link-group") { $l_grp = $val} } return 0; }
as the final part of the wanted_c function. Everything works fine now, except since I am using diagnostics I get:
Variable "%info" will not stay shared at permmy6.pl line 372 (#1) (W closure) An inner (nested) named subroutine is referencing a lexical variable defined in an outer subroutine. When the inner subroutine is called, it will probably see the value of the outer subroutine's variable as it was before and during the *first +* call to the outer subroutine; in this case, after the first call to th +e outer subroutine is complete, the inner and outer subroutines will no longer share a common value for the variable. In other words, the variable will no longer be shared. Furthermore, if the outer subroutine is anonymous and references a lexical variable outside itself, then the outer and inner subroutines will never share the given variable. This problem can usually be solved by making the inner subroutine anonymous, using the sub {} syntax. When inner anonymous subs that reference variables in outer subroutines are called or referenced, the +y are automatically rebound to the current values of such variables.
Any thoughts?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Permissions Utility Script for sysadmins - seeking comments
by hv (Prior) on Apr 22, 2004 at 09:19 UTC |