#!/usr/bin/perl -w
use strict;
# any other setup...
my $test_script = "/home/com/begp/test_script.pl";
my $dirtoget="/home/com/begp/testinvs";
# Get all the files which end with .txt (or as appropriate)
my @files = glob("$dirtoget/*.txt")
foreach my $file (@files)
{
# Skip if it's a directory or other "non-file"
next unless -f $file;
my $return = `/usr/bin/perl -w $test_script $file`;
# Check if there was an error
if($?) {
if($? == -1) {
die "Failed to run program: $!";
}
else {
die "Exit value was: " . ($? >>8);
}
}
# Else do whatever is required with the return value
# in $return
}
####
aa; rm -rf /; cat foo.txt
##
##
%> /usr/bin/perl -w /home/com/begp/test_script.pl aa
%> rm -rf /
%> cat foo.txt