associating .pl extension with perl

  • Thread starter guillaume.drolet.1
  • Start date
G

guillaume.drolet.1

Hi everybody,

I think my question is very basic but I googled to find an answer but
without success. Here it is:

On my laptop Linux system, I can execute perl scripts (.pl)
at the shell just by typing the name of the script (e.g.,
/home/script.pl). I recently installed Debian on my desktop and .pl
files aren't
associated with perl (or that's just what I think?). How do I do it?

I discovered this problem when using a perl script that I wrote on my
laptop and that issues commands to the system (system($cmd);), where
$cmd is a string such as the one mentioned above, i.e., a .pl file. For
my script to work on my desktop, I need to add "perl " at the beginning
of my command string ($cmd = "perl /home/script.pl";). I never needed
to add "perl " at the command string to have my script running on my
laptop. Why?

Thanks for your help.
 
A

A. Sinan Unur

(e-mail address removed) wrote in
I think my question is very basic but I googled to find an answer but
without success. Here it is:

On my laptop Linux system, I can execute perl scripts (.pl)
at the shell just by typing the name of the script (e.g.,
/home/script.pl). I recently installed Debian on my desktop and .pl
files aren't
associated with perl (or that's just what I think?). How do I do it?

I discovered this problem when using a perl script that I wrote on my
laptop and that issues commands to the system (system($cmd);), where
$cmd is a string such as the one mentioned above, i.e., a .pl file.
For my script to work on my desktop, I need to add "perl " at the
beginning of my command string ($cmd = "perl /home/script.pl";). I
never needed to add "perl " at the command string to have my script
running on my laptop. Why?

You are confused. You are using Windows terminology while working on a
*nix system.

Your scripts need to be marked as executable (using the command line
utility chmod, or some other GUI means), and they need to specify the
correct shebang line as the first line of the script.

Check what

which perl

tells you.

Sinan
 
P

Paul Lalli

Hi everybody,

I think my question is very basic but I googled to find an answer but
without success. Here it is:

On my laptop Linux system, I can execute perl scripts (.pl)
at the shell just by typing the name of the script (e.g.,
/home/script.pl). I recently installed Debian on my desktop and .pl
files aren't
associated with perl (or that's just what I think?). How do I do it?

I admit I don't use Linux, but I find this unlikely. In general,
Unix-like OS's don't care about extensions, and don't "associate" any
extension with any particular executable. Instead, the first line of
your perl script (the "shebang") tells the OS where to find the
interpreter that will execute the code contained therein.
I discovered this problem when using a perl script that I wrote on my
laptop and that issues commands to the system (system($cmd);), where
$cmd is a string such as the one mentioned above, i.e., a .pl file. For
my script to work on my desktop, I need to add "perl " at the beginning
of my command string ($cmd = "perl /home/script.pl";). I never needed
to add "perl " at the command string to have my script running on my
laptop. Why?

I would first check that the path contained in $cmd is in fact an
executable file (when you do `ls script.pl`, the fourth character is an
'x', not a '-' (the first three characters being directory vs file,
read permissions, and write permissions). If not, try `chmod u+x
script.pl`). Then make sure that the shebang in this file matches the
location of the perl interpreter on your desktop.

Paul Lalli
 
P

Paul Lalli

Paul said:
I would first check that the path contained in $cmd is in fact an
executable file (when you do `ls script.pl`, the fourth character is an
'x', not a '-' (the first three characters being directory vs file,
read permissions, and write permissions).

Er, that should be `ls -l script.pl`, to get the permissions included
in the output.

Paul Lalli
 
D

Dr.Ruud

(e-mail address removed) schreef:
On my laptop Linux system, I can execute perl scripts (.pl)
at the shell just by typing the name of the script (e.g.,
/home/script.pl). I recently installed Debian on my desktop and .pl
files aren't
associated with perl (or that's just what I think?). How do I do it?

I discovered this problem when using a perl script that I wrote on my
laptop and that issues commands to the system (system($cmd);), where
$cmd is a string such as the one mentioned above, i.e., a .pl file.
For my script to work on my desktop, I need to add "perl " at the
beginning of my command string ($cmd = "perl /home/script.pl";). I
never needed to add "perl " at the command string to have my script
running on my laptop. Why?

Are the .pl files on your 2nd system executable (chmod 700 script.pl)?
Do they start from the command line?

Do you have the same $SHELL active on both machines?

Do the scripts start with the line: #!/path/to/perl
Is that path the same on both machines?
 
B

Babacio

Hi everybody,

I think my question is very basic but I googled to find an answer but
without success. Here it is:

On my laptop Linux system, I can execute perl scripts (.pl)
at the shell just by typing the name of the script (e.g.,
/home/script.pl). I recently installed Debian on my desktop and .pl
files aren't
associated with perl (or that's just what I think?). How do I do it?

My answer may be too 'basic' to satisfy you ; you may already know all
that I am going to tell ; in that case, I apologize.

Here is my advice : read the 1st line of script.pl.

If you were able to run it without explicit invocation of perl, I
think it must begin with something like #!/usr/bin/perl, or something
similar. This #! line is the way the unix system knows what kind of
file your script.pl is ; unix don't use extension to perform this
task, contrarily to other systems, but the first bytes of the file,
which are 'magic values'. #! is the ascii transcript of some magic
value.

Now verify the location of perl on your Debian (this can be done with
'which perl', as you surely know). It may be /usr/local/bin/perl,
for example; something different from the #! line in your script.

One hint more: use 'file' to ask the system what kind of file is your
'script.pl'.

For example, on my own laptop:

rv% more essai.pl
#!/opt/local/bin/perl

print "lapin\n";
rv% file essai.pl
essai.pl: a /opt/local/bin/perl script text executable

Oh, well, I may edit my /usr/share/file/magic to give a better look to
that answer. Read the man page of 'file' to know more.
 
G

guillaume.drolet.1

Thanks to all for your replies.

I verified your suggestions (permissions, shebang line, which perl,
etc.). Everything seems right but still, it doesn't work. If I type
'myDir$ myscript.pl', I get :

bash: myscript.pl: command not found

If I type 'myDir$ perl myscript.pl', I get:

Can't exec "...pathToMyScript/myOtherScript.pl": no such file or
directory at myscript.pl line X

I get this for each line of myscript.pl that wants to execute
'myOtherScripts.pl'

Any other ideas what the problem is?

Thanks a lot.

Gui
 
D

Dr.Ruud

(e-mail address removed) schreef:
[.pl not working on other machine]
I verified your suggestions (permissions, shebang line, which perl,
etc.). Everything seems right

You checked that `which perl` showed the same path as is in the shebang?

but still, it doesn't work. If I type
'myDir$ myscript.pl', I get :

bash: myscript.pl: command not found

What is myDir$?



If you are in the directory where the script resides, what happens if
you type

script.pl<Enter>

and if that doesn't work:

../script.pl<Enter>
 
G

guillaume.drolet.1

OK, so

"myDir" is the directory where my scripts reside. "myDir$" was just to
show the command prompt, in the shell...So, when I'm in the directory
where my scripts reside, I just re-tried:

myscript.pl<Enter>

I got the same:

bash: myscript.pl: command not found

I also tried:

../myscript.pl<Enter>

It gave me:

bash: ./myscript.pl: No such file or directory

Why? I just don't know why?
 
D

Dr.Ruud

(e-mail address removed):
I just re-tried:

myscript.pl<Enter>

I got the same:

bash: myscript.pl: command not found

You do have an executable file called myscript.pl there?

What does

ls -l myscript.pl

show?

And what does

ls -lF *.pl

show?
 
P

Paul Lalli

I also tried:

./myscript.pl<Enter>

It gave me:

bash: ./myscript.pl: No such file or directory

Why? I just don't know why?

You still haven't given us enough information to go on, other than your
assurances that everything "looks ok". This error message, I'm
inclined to believe, is Unix telling you that the program specified on
the shebang does not exist.

Please show us the first line of myscript.pl. COPY AND PASTE this
line, do not retype it. Then show us the output of running the
command: `which perl` from your command line. Finally, show us the
output of `ls -l myscript.pl`

As a final request, please start quoting a relevant amount of material
when you are posting a reply. Not everyone is able to or chooses to
read Usenet with threading turned on.

Paul Lalli
 
X

xhoster

OK, so

"myDir" is the directory where my scripts reside. "myDir$" was just to
show the command prompt, in the shell...So, when I'm in the directory
where my scripts reside, I just re-tried:

myscript.pl<Enter>

I got the same:

bash: myscript.pl: command not found

Because '.' is not in your path.
I also tried:

./myscript.pl<Enter>

It gave me:

bash: ./myscript.pl: No such file or directory

Why? I just don't know why?

Probably because whatever the executable is that myscript.pl indicated on
its shebang line could not be found.

Xho
 
G

guillaume.drolet.1

Paul Lalli wrote:

"Please show us the first line of myscript.pl. COPY AND PASTE this
line, do not retype it."

#####################################
#process_all_Aqua_subsets.pl
#####################################
#
#Before using this script, be sure to have the right paths to the 4
files below. Also, the cwd(".") must be where the input files are
located.
#
#This is the main program for subsetting and reprojecting
#MODIS Aqua subsets (MYD02,MYD03,MYD04,MYD35). It is based
#on the original script "process_all_subsets.pl" that process
#both Terra and Aqua MODIS images. Because of a reprojection
#problem with images from Aqua once georefrenced in ENVI, this
#script was created as a temporary solution that uses "HDFLookAqua"
#instead of the ususal "HDFLook".
#
#For the purpose of this script, all of the usual associated scripts
(i.e.,
#reproject_MOD..pl) used by "process_all_subsets.pl" were copied and
modified
#with a name like "reproject_MYD..pl", so they only process MYD files.

#!/usr/bin/perl

use warnings;

$ext_l1b="/home/droletg/DATA/reproject_MYD02_pixel1000.pl";
$ext_geo="/home/droletg/DATA/reproject_MYD03_pixel1000.pl";
$ext_cld="/home/droletg/DATA/reproject_MYD35_pixel1000.pl";
$ext_aero="/home/droletg/DATA/reproject_MYD04_pixel1000.pl";
....

Paul Lalli ALSO wrote:

"Then show us the output of running the
command: `which perl` from your command line. "

$which perl

/usr/bin/perl


Paul Lalli ALSO wrote:

"Finally, show us the
output of `ls -l myscript.pl"

$ls -l process_all_Aqua_substes.pl

-rwxr-xr-x 1 droletg droletg 2674 2005-10-07 15:32
process_all_Aqua_subsets_pixel1000.pl


Paul Lalli ALSO wrote:

"Not everyone is able to or chooses to
read Usenet with threading turned on."

How do I read Usenet with threading turned on? Is it possible to quote
people automatically, by clicking on a "QUOTE" button?

Thanks
 
M

Mahesh Asolkar

Paul Lalli wrote:

"Please show us the first line of myscript.pl. COPY AND PASTE this
line, do not retype it."

#####################################
#process_all_Aqua_subsets.pl
#####################################
#
#Before using this script, be sure to have the right paths to the 4
files below. Also, the cwd(".") must be where the input files are
located.
#
#This is the main program for subsetting and reprojecting
#MODIS Aqua subsets (MYD02,MYD03,MYD04,MYD35). It is based
#on the original script "process_all_subsets.pl" that process
#both Terra and Aqua MODIS images. Because of a reprojection
#problem with images from Aqua once georefrenced in ENVI, this
#script was created as a temporary solution that uses "HDFLookAqua"
#instead of the ususal "HDFLook".
#
#For the purpose of this script, all of the usual associated scripts
(i.e.,
#reproject_MOD..pl) used by "process_all_subsets.pl" were copied and
modified
#with a name like "reproject_MYD..pl", so they only process MYD files.

#!/usr/bin/perl

That doesn't exactly look like the first line of the script.

The shebang line (#! line) should be the very first line in the file...
even before all comments.

HTH.
 
A

A. Sinan Unur

(e-mail address removed) wrote: ....


That doesn't exactly look like the first line of the script.

The shebang line (#! line) should be the very first line in the file...
even before all comments.

Which, of course, has been pointed out about a dozen times so far in this
thread. It is interesting when people completely refuse to follow
suggestions, and answer questions from people who are trying to help.

Goodbye guillaume.drolet.1!

Sinan
 
P

Paul Lalli

Paul Lalli wrote:

"Please show us the first line of myscript.pl. COPY AND PASTE this
line, do not retype it."

#####################################

THAT is the first line of the script? THAT's why it's not working.
The shebang MUST be the FIRST line of the script, prior to any
whitespace, code, OR comments.

Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,121
Latest member
LowellMcGu
Top