in reply to Need help understanding legacy code with forking (was : SOS)

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: Re: SOS
by virtualsue (Vicar) on Apr 28, 2002 at 10:36 UTC
    $datdir is in fact 'magically' created - by Perl. There was plenty of code to work with in the root node, so this comment of yours, besides being mostly wrong, looks peevish at best.

    It's hard not to notice that your nodes often appear in the Worst Nodes section. Do you understand why, or even care?

    Update: While I'm not sorry I posted this follow-up, I'd like to ask that people hold off on downvoting BUU's node. It doesn't deserve to go any lower, IMO.

      Thank you for the help.
      Whats the worst node thing ??
      I did format my question with the CODE tag...
      Thanks again,
      Oz
      p.s:Can I bug u directly with questions?
        
        Whats the worst node thing ?? 
        
        Don't worry about that right now. You can follow the link in my other node if you're curious.
        
        I did format my question with the CODE tag...
        
        I take that back, then. I was more concerned about the indenting, which in this case made it look as though all the code was part of the foreach {} loop.
        
        p.s:Can I bug u directly with questions?
        
        Yes, though your best bet is to try the PerlMonks Chatterbox. You can almost always find someone there who is willing to help out.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Re: SOS
by perl_virgin (Initiate) on Apr 28, 2002 at 15:56 UTC
    Hi, Thanks for replying. Here is the complete function starting from the comments. Please let me know what you think. Thanks.
    #--------------------------------------------------------------------- +---- # Check for the existence of the directories requested by the user. #--------------------------------------------------------------------- +---- # sub YCHECK { my ($user, $sid, $oraserv, $site, @dates) = @_; my ($server, $path, $ytmp, $datdir, $fullpath, $tmpfull, $what, $w +hat2); my @vdates = (); my %paths = (); my %tmps = (); my $njobs = 0; my $maxnjobs = 10; if (($site =~ "l",) || ($site =~ "c") || ($site =~ "n") || ($site =~ "w")) { $site = "l"; $server = "yos.$site.com"; $path = "/people/$user/$oraserv/$sid/arch/"; $ytmp = "/tmp/$oraserv/$sid/"; } elsif ($site =~ /wf/) { $server = "yos.$site.com"; $path = "/people/$user/$oraserv/$sid/arch/"; $ytmp = "/tmp/$oraserv/$sid/"; } elsif ($site =~ "h") { $server = "yos.$site.com"; $path = "/people/$user/$oraserv/$sid/arch/"; $ytmp = "/tmp/$oraserv/$sid/"; } else { die "$site is not a valid site for this script please contact "; } foreach $datdir (@dates) { $fullpath = (join ('', $path, $datdir)); $fulltmp = (join ('', $ytmp, $datdir)); my $pid = fork(); if ($pid == 0) { $what = `rsh $server ls -ld $fullpath`; if ($what =~/\S/) { $what2 = `rsh $server mkdir -p $fulltmp`; if ($what2 !~/\S/) { exit 1; } } exit 0; } $paths{$pid} = $fullpath; $njobs++; while ($njobs >= $maxnjobs) { $waitpid = wait(); if ($?) { push(@vdates, $paths{$waitpid}); } $njobs--; } } while ($njobs > 0) { $waitpid = wait(); if ($?) { push(@vdates, $paths{$waitpid}); } $njobs--; } my @sorteddates = sort(@vdates); return(@sorteddates); }
      Maybe this wasn't part of your original question, but your more complete posting of code contains some things you ought to fix. In particular, this condition has a couple problems:
      if (($site =~ "l",) || ($site =~ "c") || ($site =~ "n") || ($site =~ "w"))

      Apart from the extra comma, the use of the "=~" operator with literal strings seems wrong here; the intention was either this:
      if ( $site =~ /[lcnw]/ )
      or this:
      if ( $site eq "l" or $site eq "c" or $site eq "n" or $site eq "w")

      which could (should) be stated this way:
       if ($site =~ /^[lcnw]$/)

      The other problem is that, as written, it actually acts like the first alternative, which means that it will match when $site contains "wf", and as a result, the subsequent condition will never get a chance to work:

      elsif ($site =~ /wf/)

      Also, you are repeating the same statements in these three successive conditional blocks.

      If you really want "$site" values containing "wf" and "h" to remain unchanged, while other "$site" values (that might contain a "w") get changed to "l" -- and in all other respects these cases get the same treatment -- do it this way (assuming that "$site" should be a single letter or "wf" only):

      if ($site =~ /^([lcnh]|wf)$/) { # one block handles all cases $site = "l" unless ( $site =~ /(h|wf)/ ); $server = "yos.$site.com"; # and so on }