associating .pl extension with perl

Discussion in 'Perl Misc' started by guillaume.drolet.1@ulaval.ca, Oct 7, 2005.

  1. Guest

    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.
     
    , Oct 7, 2005
    #1
    1. Advertising

  2. wrote in
    news::

    > 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 <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Oct 7, 2005
    #2
    1. Advertising

  3. Paul Lalli Guest

    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
     
    Paul Lalli, Oct 7, 2005
    #3
  4. Paul Lalli Guest

    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
     
    Paul Lalli, Oct 7, 2005
    #4
  5. Dr.Ruud Guest

    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."
     
    Dr.Ruud, Oct 7, 2005
    #5
  6. Babacio Guest

    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.
     
    Babacio, Oct 7, 2005
    #6
  7. Guest

    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
     
    , Oct 7, 2005
    #7
  8. Dr.Ruud Guest

    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."
     
    Dr.Ruud, Oct 7, 2005
    #8
  9. Guest

    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?
     
    , Oct 7, 2005
    #9
  10. Dr.Ruud Guest

    :

    > 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."
     
    Dr.Ruud, Oct 7, 2005
    #10
  11. Paul Lalli Guest

    wrote:
    > 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
     
    Paul Lalli, Oct 7, 2005
    #11
  12. Guest

    wrote:
    > 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

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Oct 7, 2005
    #12
  13. Guest

    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
     
    , Oct 7, 2005
    #13
  14. wrote:
    > 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.
    --
    Mahesh
     
    Mahesh Asolkar, Oct 8, 2005
    #14
  15. "Mahesh Asolkar" <> wrote in
    news::

    > wrote:

    ....

    >> #!/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.


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

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Oct 8, 2005
    #15
  16. Paul Lalli Guest

    wrote:
    > 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
     
    Paul Lalli, Oct 9, 2005
    #16
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vpcs
    Replies:
    0
    Views:
    1,566
  2. News
    Replies:
    4
    Views:
    424
    Eliyahu Goldin
    Jul 20, 2004
  3. Eliyahu Goldin

    Re: associating c# events with html objects

    Eliyahu Goldin, Aug 4, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    460
    Eliyahu Goldin
    Aug 4, 2004
  4. =?Utf-8?B?Tm92aWNl?=
    Replies:
    1
    Views:
    479
    John Saunders
    Sep 23, 2004
  5. =?Utf-8?B?YWJvb21hcjEw?=
    Replies:
    0
    Views:
    330
    =?Utf-8?B?YWJvb21hcjEw?=
    Oct 13, 2004
Loading...

Share This Page