1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
use 5.012; use warnings; use File::Spec; my ($sep, $exe) = do { if ($^O =~ /^MSWin/) { (';', '.exe') } else { (':', '') } }; sub findgs { for my $dir (split $sep, $ENV{PATH}) { my $_ = File::Spec->catfile($dir, "gs$exe"); return $_ if -x; } } if (my $gs = findgs) { say "ghostscript found: $gs"; } else { warn "ghostscript not found"; }