I have a file, tmp.pl, and wish to include my own perl module file, util.pm:
package util;
our @EXPORT = qw(execute);
sub execute {
my $cmd = shift;
my $return = 'exit';
my $die = 1;
if ($return !~ m/^(exit|stdout|stderr|all)$/i) {
die "you gave $return = "$return", while this subroutine only accepts ^(exit|stdout|stderr)$";
}
my ($stdout, $stderr, $exit) = capture {
system( $cmd )
};
if (($die == 1) && ($exit != 0)) {
say STDERR "exit = $exit";
say STDERR "STDOUT = $stdout";
say STDERR "STDERR = $stderr";
die "$cmdn failed";
}
if ($return =~ m/^exit$/i) {
return $exit
} elsif ($return =~ m/^stderr$/i) {
chomp $stderr;
return $stderr
} elsif ($return =~ m/^stdout$/i) {
chomp $stdout;
return $stdout
} elsif ($return =~ m/^all$/i) {
chomp $stdout;
chomp $stderr;
return {
exit => $exit,
stdout => $stdout,
stderr => $stderr
}
} else {
die "$return broke pigeonholes"
}
return $stdout
}
1;
which I include in the current directory thus:
#!/usr/bin/env perl
use Cwd 'getcwd';
push @INC, getcwd();
use util;
use warnings FATAL => 'all';
use autodie ':default';
which gives me an error:
Can't locate util.pm in @INC (you may need to install the util module) (@INC entries checked:
How can I include the simple module in a directory with other scripts?