Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

assosiating .pl files with perl on linux

by abhishes (Friar)
on Apr 29, 2004 at 07:13 UTC ( [id://349036]=perlquestion: print w/replies, xml ) Need Help??

abhishes has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,

I have been a active state perl user on windows. There if I type
tele.pl params

on the console, the perl interperter automatically comes into play. also I can run this from anywhere so long as the directory which contains my tele.pl script is in the path.

Now I am on linux (mandarke 9.2, gnome 2.4) and I try to do the same thing (add my script directory to the path)

but I get a slew of errors

/mnt/windows/myapps/perl/hptele.pl: line 1: use: command not found : command not found/perl/hptele.pl: line 1: /mnt/windows/myapps/perl/hptele.pl: line 2: use: command not found : command not found/perl/hptele.pl: line 2: : command not found/perl/hptele.pl: line 3: /mnt/windows/myapps/perl/hptele.pl: line 4: my: command not found : command not found/perl/hptele.pl: line 4: : command not found/perl/hptele.pl: line 5: /mnt/windows/myapps/perl/hptele.pl: line 6: syntax error near unexpected token `defined' 'mnt/windows/myapps/perl/hptele.pl: line 6: `unless (defined($namePattern))

I will grately appriciate any help in this regard.

regards,
Abhishek.
  • Comment on assosiating .pl files with perl on linux

Replies are listed 'Best First'.
Re: assosiating .pl files with perl on linux
by Corion (Patriarch) on Apr 29, 2004 at 07:19 UTC

    Making any file under Linux executable is a two-fold process:

    1. First, you need to mark the file as executable by setting it's "executable" bit. You seem to have done that, as you see some errors.
    2. Second, for text files to be executable, you must make the first line of the script point to the interpreter it is to be executed with. You don't seem to have that, as you get some errors about commands not being found. Try the below script as a starting point.
    #!/usr/bin/perl -w use strict; print "Hello World from Perl\n";

    The first line ("hashbang line", due to the first to characters in it) must point to where perl is located on your machine.

        I hate to be pedantic, but that is more commonly called the 'shebang' line, not 'hashbang'.
        If you find something in the Jargon file, that means that most likely no one really talks that way.

        I think 'hashbang' is pretty common, though 'shebang' is still heard occasionally.

Re: assosiating .pl files with perl on linux
by gellyfish (Monsignor) on Apr 29, 2004 at 09:14 UTC

    Corion is, of course, completely correct. You can find more about running perl programs in the perlrun manpage.

    However, just for fun of course, you can make linux behave in a similar fashion to windows. If you run the following as 'root' in the shell:

    modprobe binfmt_misc + echo ':perl:E::pl::/usr/bin/perl:'>/proc/sys/fs/binfmt_misc/register
    (Adjusting the path to perl as necessary) Then the Linux kernel will recognise the extension .pl as a program that will be run by perl without requiring a shebang line - of course the file still has to be executable. You probably don't want to do this on a production machine however and YMMV as regards the kernel configuration.

    /J\

Re: assosiating .pl files with perl on linux
by z3d (Scribe) on Apr 29, 2004 at 14:18 UTC
    Are you asking how to get gnome (or kde, I suppose, the only two that come to mind with built in filebrowsers) to recognize the .pl extension? In Nautilus (gnome's browser) you can set up a file association to /usr/bin/perl, telling it to run in terminal. In KDE, you can setup a similar execute association.

    Unless you meant on the console, then listen to the others :)



    "I have never written bad code. There are merely unanticipated features."
Re: assosiating .pl files with perl on linux
by zentara (Cardinal) on Apr 29, 2004 at 20:16 UTC
    Not that I use .pl extensions, but midnight commander handles extensions very well on linux. Look at the mc.ext file usually in /usr/share/mc or /usr/local/share/mc. Just hit enter on the .pl file and it will invoke perl if you set it up right. I like the way it launches .html files and audio files.

    I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://349036]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2025-01-20 04:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (59 votes). Check out past polls.