On 11/10/06, Tony Heal <[EMAIL PROTECTED]> wrote:
OK, the has to be an easy way to call one script OR another from within
another, but I would like suggestions, as this does not work because there
is no RegEx to put from here.





#!/usr/bin/perl



if ( -f '/usr/local/custom/backup.pl' || '/usr/local/custom/backup.sh' ) {
system ("$&"); }


I can see a couple of ways to handle this. The easy way would be:

  foreach (qw{ /usr/local/custom/backup.pl /usr/local/custom/backup.sh}) {
     system("$_") && last if -f;
  }

If you're really attached to the or construct for some reason, this
should work, too:

  if ( -f '/usr/local/custom/backup.pl' || -f
'/usr/local/custom/backup.sh' ) { #notice the second '-f'
     $fi = (stat _)[1], system(eval {$_ = `find /usr/local/custom
-inum $fi`; s/\s*//; $_});
  }

That's just plain ugly, though, not to mention dangerous. You could
make things better by replacing the find invocation with some
equivalent File::Find code, but it'd still be ugly, and slow.

You could also go for something like

  my $file;
  if ( ($file = '/usr/local/custom/backup.pl' && -f $file) or ( $file
= '/usr/local/custom/backup.sh' && -f $file) ) {
     system("$file");
  }

Unfortunately, there's no good way to one of those filenames back
unless you cache it somewhere or coerce the logic into a control
structure, like foreach, that automatically assigns $_.

HTH,

--jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to