Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > associating .pl extension with perl

Reply
Thread Tools

associating .pl extension with perl

 
 
guillaume.drolet.1@ulaval.ca
Guest
Posts: n/a
 
      10-07-2005
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.

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      10-07-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in
news:(E-Mail Removed) oups.com:

> 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
--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      10-07-2005
(E-Mail Removed) wrote:
> 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

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      10-07-2005
Paul Lalli wrote:
> 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

 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      10-07-2005
(E-Mail 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?

--
Affijn, Ruud

"Gewoon is een tijger."
 
Reply With Quote
 
Babacio
Guest
Posts: n/a
 
      10-07-2005
(E-Mail Removed) writes:

> 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.

--
Bé erre hue ixe eu elle, Bruxelles.
 
Reply With Quote
 
guillaume.drolet.1@ulaval.ca
Guest
Posts: n/a
 
      10-07-2005
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

 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      10-07-2005
(E-Mail 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>


--
Affijn, Ruud

"Gewoon is een tijger."

 
Reply With Quote
 
guillaume.drolet.1@ulaval.ca
Guest
Posts: n/a
 
      10-07-2005
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?

 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      10-07-2005
(E-Mail 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?

--
Affijn, Ruud

"Gewoon is een tijger."
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Associating data with their equivalent values from other tables =?Utf-8?B?YWJvb21hcjEw?= ASP .Net 0 10-13-2004 05:59 PM
Write web controls out to a page and associating event handlers =?Utf-8?B?Tm92aWNl?= ASP .Net 1 09-23-2004 06:31 PM
Re: associating c# events with html objects Eliyahu Goldin ASP .Net 0 08-04-2004 01:40 PM
Help with finding datagrid and associating event News ASP .Net 4 07-20-2004 03:19 PM
problem with associating checkbox in perl-cgi vpcs Perl 0 09-08-2003 03:45 PM



Advertisments