Advertisement

02.23.2008 at 11:29AM PST, ID: 23187451
[x]
Attachment Details

Designating filename only of script being executed - not full $0 path value

Asked by dneill8 in Perl Programming Language

Tags: Perl

I'm trying to spit back a "Usage: " clause the prompts the user to execute the script with certain parameters.  If I use $0 to designate the name of the script being used, I am printing out the whole pathname to the script (perl, v5.8.8 built for MSWin32-x86-multi-thread).  I'd rather just repeat the filename of the script being used.  I captured a value for cwd (or pwd, if you prefer) and stripped that away from $0.  I've written the below to repeat the scriptname and then a <filename> I'd like used as a parameter, but it seems a fairly tortured way of going about the task.  Does anyone have a cleaner solution?

TIAStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
#!/usr/bin/perl -w
 
use Cwd;
my $currWorkDir = &Cwd::cwd();
$currWorkDir =~ s/\//\\\\/g;
$0 =~ s/^($currWorkDir)\\//;
 
if (@ARGV < 1)	{
	print " Usage: $0 <filename>\n";
	exit;
}
 
Loading Advertisement...
 
[+][-]02.23.2008 at 12:02PM PST, ID: 20966398

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02.23.2008 at 12:22PM PST, ID: 20966491

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.23.2008 at 12:30PM PST, ID: 20966523

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: Perl
Sign Up Now!
Solution Provided By: Tintin
Participating Experts: 2
Solution Grade: A
 
 
[+][-]02.23.2008 at 12:30PM PST, ID: 20966525

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.23.2008 at 12:40PM PST, ID: 20966578

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.23.2008 at 12:43PM PST, ID: 20966595

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.23.2008 at 01:00PM PST, ID: 20966666

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628