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?
Perl

Avatar of undefined
Last Comment
peetm
Avatar of ozo
ozo
Flag of United States of America image

Avatar of peetm
peetm
Flag of United Kingdom of Great Britain and Northern Ireland image

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
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
Avatar of Tintin
Tintin

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of peetm
peetm
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
Avatar of Tintin
Tintin

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
peetm
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

@Tintin

Don't have cygwin; and have no interest in having a **ux version -- Windows is what I'd like
[no offence meant!]
Avatar of Adam314
Adam314

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
peetm
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

>>File::Which

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

Perl
Perl

Perl is a high-level, general-purpose, interpreted, dynamic programming languages with over 25 years of development. Perl 5 runs on over 100 platforms from portables to mainframes and is suitable for both rapid prototyping and large-scale development projects. Perl gained widespread popularity as a Common Gateway Interface (CGI) scripting language, in part due to its regular expression and string parsing abilities. In addition to CGI, Perl is used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications.

26K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo