?
Solved

What/where do I set path for perl

Posted on 2003-03-18
5
Medium Priority
?
197 Views
Last Modified: 2012-05-04
I currently have to type perl in front of a perl script in order to get it to execute. What do I have to do so I don't have to type perl in front of the script name? An addition to my .profile?????
0
Comment
Question by:894359
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Accepted Solution

by:
Thunder27 earned 200 total points
ID: 8161169
1) Make sure your script identifies itself to Unix as a Perl script by having this as its first line:  #!/usr/bin/perl
2) Turn on the Unix "execute" permission for your script file by typing this command at the Unix prompt:  $ chmod +x yourscript.pl
3) Run your script by typing its filename.
0
 

Expert Comment

by:sykkn
ID: 8161636
I would like to extend Thunder27's #3 ...

run your script using either ./scriptname.pl if in the script is in the current working directory or /path/to/scriptname (full path) ... and possible relative path, but and explanation of that is beyond the scope of this question.

Hope that helps.
0
 
LVL 6

Expert Comment

by:holli
ID: 8167696
in a windows/dos environment you can use the following trick:

name this file perlscript.bat:

@ECHO OFF
IF EXIST %0 perl -x %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
IF EXIST %0 GOTO BATCHEND
perl -x %0.BAT %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO BATCHEND

#!perl
print "hello from batched perl!";

__END__
:BATCHEND

so typing
perlscript or perlscript.bat will both print "hello from batched perl!"

using nt/2000 and activeperl you can also start a script by typing its full name (including the .pl extension), followed by the arguments:

foo.pl arg1 arg2 ...


holli
0
 
LVL 1

Expert Comment

by:Thunder27
ID: 8168471
Along the same lines as holli mentioned (in the UNIX/LINUX environment though), you can create a shell script to run the perl script:

file domyperl.sh:
cd /usr2/db/backup_scripts
perl myscript.pl >>logs/errs.log 2>&1

Save it (i.e., domyperl.sh).
Chmod to 700


then run from the command line as ./domyperl.sh
0
 

Author Comment

by:894359
ID: 8207490
It was my stupid mistake!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question