I know the format and scripting are probably pretty backwards but I
seem to recall it being important to have a `return' line in a
function. 

The code below was a script by itself but now I need to turn it into a
function inside a larger script... I've done something that sort of
works but fails on a specific file name that looks like `.#somefile'.

I'll show the code the way I've tried to turn it into a sub routine.
So, I'd like comments both on how to write this more like a proper sub
routine and any other why ideas.

What the sub is supposed to do is plow thru a couple of directories and
reset the proper owner and group after some other operations have
changed them.

Its called like this in a getops operation:

if($opt_o ) {
  if (@ARGV) {
    usage();
    print "The \`-o' flag must be used by itself and\n",
          " \`-o' flag requires user to be root .. exiting\n ";
    exit;
  }
  chOwnGrp();
  exit;
}

sub chOwnGrp {
  use File::Find;
  my $buffer = '/merb';
  my $module = '/usr/local/common/merc';
  my $uname = $ENV{'LOGNAME'};
  my $uid = '1000';
  my $gid = '1050';

  if ($uname =~ /root/) {
    print "Would you like to set owner:group on BUFFER and MODULE?\n",
          "If so, we will run chown -R $uid:$gid $buffer and\n",
          "chown -R $uid:$gid $module\n",
          "[y/n] > ";

    my $answer = <STDIN>;
    if ($answer =~ /^y$/) {
      find(
           sub {
             chown $uid, $gid, $_ or warn "could not chown '$_': $!";
           },
           $buffer, $module
          );
    }
  } else {
    print "You must be root to run with this flag (-o)  effectively.. 
exiting\n";
    print "Not root - tripped at line: <" . __LINE__ . ">\n";
    exit;
  }
}


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to