#!/usr/bin/perl
use strict;

my(@array1,@array2) = (),();

if (time) {

   @array1 = `perl -e "sleep 2; print 1, qq[\n\n]"`;

   print(qq[Find one completed.  Found: @array1])
}
if (time) {

   @array2 = `perl -e "sleep 2; print 2, qq[\n\n]"`;

   print(qq[Find two completed  Found: @array2])
}

@array1=`perl -e "foreach (0..10000000) { print '' } print 1, qq[\n\n]"`;

print(qq[Find one completed.  Found: @array1]);

@array2=`perl -e "foreach (0..10000000) { print '' } print 1, qq[\n\n]"`;

print(qq[Find two completed.  Found: @array2]);

exit;


# test.pl-------
# <perlcode>

   # define directory, search term pairs
   my(@search) = (['cgi-bin', 'pl'], ['htdocs', 'html']);

   # perform look ups for each search pair
   foreach (@search) {

      # each search pair has a pair of values; the first is
      # the directory name, the second is the search term
      my($dir, $str) = @{ $_ };

      # use quotemeta() to provide the necessary shell escapes for any
      # arguments we pass through the shell to find.pl  This is important
      # if a directory name has spaces, if your search term were to include
      # a double-quote character, and in many other similar situations.
      # if you extend this script to take arguments from @ARGV, this makes
      # sure you're prepared.  Bad things can happen unless you do this!
      $dir = quotemeta($dir) and $str = quotemeta($str);

      # strike up a conversation with find.pl and ask it to do some look ups
      # for each of our search pairs
      my($pipe) = open(FILE, qq[./find.pl "$dir" "$str" |]);

      # print out what find.pl sent back.
      print while (<FILE>) and close(FILE)
   }

   # whatever...
   print(<<__done__);

   ALL DONE.

__done__

# </perlcode>


# find.pl--------
# <perlcode>

   # obtain caller's argument for the directory to search, & the search string
   my($searchdir) = shift(@ARGV)||die(qq[need dir name]);
   my($searchstr) = shift(@ARGV)||die(qq[need search str]);

   # laziness (see <http://www.perldoc.com/perl5.6.1/pod/perl.html#NOTES>)
   my($prefix)    = q[/usr/people/dracula/workareas];

   # don't be stupid.  you are responsible for the security of your programming
   my(@legaldirs) = (q[cgi-bin], q[htdocs], q[foo], q[bar]);

   # foil the phreak
   die(q[I don't think so.  That isn't allowed.]) unless islegal($searchdir);

   # do the lookup now with the proper system call
   print( qx[find $prefix/$searchdir -name "*.$searchstr" -print] );

   # subroutine to check the legality of the caller's lookup request
   sub islegal {

      return unless defined($_[0]);

      foreach (@legaldirs) { return(1) if ($_[0] eq $_) }

      return(0);
   }
# </perlcode>