Link to home
Start Free TrialLog in
Avatar of peetm
peetmFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Whereis in Perl

I'd be interested to see a whereis type program written in Perl.  Whereis - as in - whereis 'this' file along my PC's path.

I've written various version in Ruby, PHP C, Java etc, and would like to compare those against a Perl implmentation [as well as to other languages].

Anyone fancy starting me off?
Avatar of ozo
ozo
Flag of United States of America image

Avatar of peetm

ASKER

Knowing nothing about Perl really - although I've a few hacked scripts on my server - does this do a whereis; and can it run in a Windows console locally?

This is *just* for curiosities sake - see www.peetm.com/blog for more efforts!
ASKER CERTIFIED SOLUTION
Avatar of Adam314
Adam314

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tintin
Tintin

You should define what features and version of whereis you mean.  The examples on your blog and examples given here are different to the results and output of the Linux whereis.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peetm

ASKER

@Tintin

>>You should define what features and version of whereis you mean.

Well, I'm not too fussy here.

For example, I've never specified that wildcards should be expanded, nor that argv[0/1] (depending upon the language) should exist, nor that I'd expect a recursive search.

Nor any other constraint; other than that; given a Windows' PATH, that, IF a file exists, that the whereis should send its output to stdout - saying where it is.

Obviously, a Perl/Python/C/Whatever program should be run from a console.

I'm really looking for the most concise, shorttest program that can do this under Windows.
Your requirements are more the output of which rather than whereis.  Here's the difference on a Linux system

$ which perl
/ramdisk/bin/perl

$ whereis perl
perl: /bin/perl /bin/perl.orig /usr/bin/perl /usr/bin/perl.orig /sbin/perl /sbin/perl.orig /usr/sbin/perl /usr/sbin/perl.orig /usr/share/man/man1/perl.1 /usr/share/man/man1/perl.1.gz

Note that my script will run on Windows if you have cygwin (or similar) installed.
Avatar of peetm

ASKER

@Tintin

Don't have cygwin; and have no interest in having a **ux version -- Windows is what I'd like
[no offence meant!]
The code I gave will run on windows just fine, as long as the File::Which module is installed.
Note that windows programs can have an extension, and the File::Which module will include that in it's search.

Meaning, if you search for perl, the File::Which module will search for perl.bat, perl.exe, perl.com, ... (a few others).

Avatar of peetm

ASKER

>>File::Which

Sounds 'Spooky' to me -- 'Blair::Witch'!