#!/usr/bin/perl -w

use strict;
use File::Spec;

if( @ARGV == 0 ) {
  print <<EOH;
Usage: $0 sample-name

if a file named samples/sample-name/sample-name.pl exists, then
changes the directory to samples/sample-name and executes
the program (via do filename)
EOH
  exit 1;
}

my( $fname, $dir ) = ( "$ARGV[0].pl",
                       File::Spec->catdir( 'samples', $ARGV[0] ) );
my( $path ) = File::Spec->catfile( $dir, $fname );

if( -f $path ) {
  use blib;
  use Cwd;

  my( $cwd ) = getcwd();
  chdir $dir;
  my( $ret ) = do $fname;
  die "$@: $!" if $@;
  die "$!" if $!;
  # probably not necessary
  chdir $cwd;
}
else {
  die "file '$path' does not exist";
}

# Local variables: #
# mode: cperl #
# End: #
