#!/usr/local/bin/perl
# This is analogous to the ksh 'whence' builtin, except that its
# arguments are treated as patterns. Thus "whence foo*" will print
# the paths of all programs whose names match foo*.

use Env::Path qw(:all);
use constant MSWIN => $^O =~ /MSWin32|Windows_NT/i ? 1 : 0;

for my $name (@ARGV) {
    $name .= '.*' if MSWIN && $name !~ /(?:\.\w+|\*)$/;
    for (PATH->Whence($name)) {
	print "$_\n";
    }
}
