Adding perl script to module distribution and making it accessible globally - perl

I'm wondering if there is a tutorial or simple way to add perl scripts which I've written to be accessible to the user globally.
for eg. you apps like Carton, Cpanm, much like how npm has an npm install -g option.
I tried placing my scripts in the bin directory of my perl package but its not working.

The App::* area of cpan contains installable tools and utilities. Looking at a small one, like App::p I saw that its structure looked like it contained a Makefile.PL that used ExtUtils::MakeMaker to define how to build test and install the relatively small perl script.
However, if you're talking about just taking a script you wrote and making it something executable by you, the user, then it's basically the same way all scripting works (apologies if you weren't asking this):
One Unix, Linux and Mac OS X when using a shell like bash:
Any file can be made executable to the user by running chmod u+x filename
An executable file should start with a magic number, for plain text files containing scripts, the shebang is that number. So start your files with (as covered in man perlintro):
#!/usr/bin/perl
use strict;
use warnings;
When specifying an executable file from the command line you can type in the full path, possibly with conveniences from your shell. EG the file is at $HOME/myscripts/runme.pl you can type that at the prompt, the expanded /home/username/myscripts/runme.pl (/Users/username/myscripts/runme.pl on Mac OS X) or ~/myscripts/runme.pl at a bash prompt. Or if runme.pl is in your current working directory: ./runme.pl
If you just type runme.pl sh and bash and many shells will search your PATH variable in order and run the first runme.pl in any of the specified paths.
So if echo $PATH gives you something like: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin and you want the example in point 3 to work with just runme.pl you should
Either move the file into one of those directories (not recommended).
Or add export PATH=$PATH:$HOME/myscripts to the bottom of your ~/.bashrc or ~/.profile file or likewise for your preferred shell. Be sure to open a new login shell session, EG close that terminal window and open a new one.
On Windows, this is an exercise left to the reader. ☺

Related

Can we run a Perl script in a browser without web server?

Is it possible to run a perl script in Activeperl without web server in windows 7.If possible what are the steps to follow?
I have simple registration form using Post method in HTML file.I'm using this HTML file in my .pl file.I'm using CGI module. While running the .pl file from the command promt the HTML file is running browser, after clicking submit button the perl script is displaying.
When you install ActivePerl, it creates a file association for .pl files, so simply double-clicking a .pl file in Explorer ("My Computer", "File Explorer", etc) will run it. This also makes it so you can run script.pl from the Windows Command Prompt.
When you install ActivePerl, it modifies your PATH to include the directory that contains perl.exe, making it so you can run perl script.pl from the Windows Command Prompt.
Finally, you can always run c:\...\bin\perl script.pl from the Windows Command Prompt.
Can you explain a bit more the exact use-case?
I think the first user in the comments gave you the best answer.
If Perl is not in your PATH environment you need to associate .pl extensions with Perl or run it via command-line ( if I remember correctly Active-Perl comes with a Perl command line tool )

Script in PATH Mac OSX terminal not working

I have the following script in my /path/to/startupscripts directory, so I can open the emacs GUI with the command 'emacs':
#!/bin/sh
/Applications/Emacs.app/Contents/MacOS/Emacs "$#"
I edited my ~/.bash_profile and added the following line
export PATH=/path/to/startupscripts/emacs:$PATH
However, the script is not working because when I type in 'emacs' into the command line emacs still opens within terminal and not the GUI like I want. Also, when I am in the /path/to/startupscripts directory and I can execute and run the script with
chmod +x emacs
./emacs
but even when I type 'emacs' afterwards it still opens within terminal. I am a bit of a beginner, and I think I am missing something painfully obvious.
The PATH should contain a directory name where your script(s) can be found, not the name of your individual script.
You probably need to source your .bash_profile:
source ~/.bash_profile
No changes made in your profile will be applied unless you source the profile or log out and back in.
Aside from that every looks like it should work.
However you may want to consider just using an alias instead of a script for this. This can be done by adding this to your profile:
alias emacs=/Applications/Emacs.app/Contents/MacOS/Emacs
That's probably a cleaner way to get the functionality you want without adding more to your PATH variable.
I hope that helps! [insert obligatory comment about how you should be using vim and not emacs :P]

path of perl scripts [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I am following the book 'Google Hacks'. It has many ready-made perl scripts, but it does not clearly say exactly where I need to save those perl scripts. I think I have to invoke these scripts from command line, but cannot figure out the location where these scripts should be stored. I am using Strawberry perl.
Also, it would be helpful I can run perl scripts from local environment setting with Internet connection, for example, to scrap Google search results. Thank you
note: I am using Apache webserver and windows 7 operating system
Are they on your server, or are they on your local machine? I'm assuming they're on your local system:
On Unix/Mac/Linux, the setup is fairly straight forward:
Make sure that the shebang points to your Perl executable. I make it #! /usr/bin/env perl which will find the perl command in my path.
Put the scripts in a directory in your $PATH variable.
On Windows, the setup is a bit more involved:
You need to setup your %PATH% environment variable to point to include your Perl scripts. You can do this by going into the System Control Panel (the easiest way is to right click on Computer on your desktop, and select Properties. Then go into Advanced Settings, and click on the Environment Varables... button on the bottom. Path is one of the System Variables.
You need to associate your *.pl suffix with your Perl executable. The problem is that Microsoft keeps changing this. However, the following works for Windows 7 and earlier:
Find a Perl script and view it in Windows Explorer. Right click on it, and open Properties. In Properties, there's an Opens with selection. Click on the Change button and select your Perl interpreter as your interpreter. Make sure the Always use the selected program to open this kind of file checkbox is checked.
Finally, you may want to set %PATHEXT% to include .pl as one of the executables. This way, you can type your Perl program without having to type the suffix all of the time. On Unix/Linux/Mac, you don't need suffixes because the shebang will point to the correct interpreter, but Windows must have a suffix associated with the executable. Now, instead of typing foo.pl on the command line, you can just type foo.
Once this is done, you can simply type in the name of your executable Perl script from any directory in the Command Prompt terminal and run your program.
The 1st thing you need to do, is to make sure that the .pl (or as some use, .plx) extension is associated in the windows registry as a perl program and that perl programs should be run by your perl.exe. At this point you should be able to run perl programs that don't require command line parameters just by double clicking them in Windows Explorer. I know that the installer for ActiveState Perl does this for you by default. I can't vouch for Strawberry.
To run them on the command line, you can just name their complete path ( C:\Mypath\Myprog.pl) or put them in a directory named in your PATH environment variable.
If you're trying to run them via Apache, you'll need to configure Apache with a CGI-BIN directory and put your CGI compatible perl programs in that directory. Again, Apache on Windows depends on the file extension associations in the registry, so make sure you've done that 1st step.

How do I get eshell working correctly in emacs?

For some reason, when I type in commands I'm used to on linux, it works perfectly, as it does in bash... But in eshell, it doesn't work.
I've narrowed the problem to a trivial and small sample, as follows:
$ du
c:/Program: command not found
$ which bash
c:/Program Files (x86)/Git/bin/bash.exe
How do I get this working? (du is whatever it is by default... It's implemented in elisp, I haven't made any unusual changes there, that is, it's a compiled lisp function in `em-unix.el')
I would've expected something along the lines of "You have used 1.3 GiB of disk space", rather than that command not found error.
It doesn't use bash.exe, but it can use du.exe, when present.
On my system:
c: gutov $ which bash.exe
which: no bash.exe in ...
c: gutov $ which du.exe
h:/Apps/System/gnuwin32/bin/du.exe
From your error message I can tell that it calls some command and fails because it doesn't properly quote the path to executable (which contains spaces). Maybe you should do M-x report-emacs-bug.
Overall, I recommend:
1) Uninstall Git and reinstall it selecting the second option when asked about your PATH environment ("Run Git from the Windows Command Prompt"). This will remove the unix tools packaged with it from PATH.
2) Install in some directory without spaces and add to PATH unix tools from GnuWin32 project, or from Eli Zaretski's ports. The latter contains fewer packages overall, but it has a much faster find, for example. You can mix them.
Alternatively, maybe you can get away with just reinstalling Git into directory without spaces.

How can I run a Perl script with ActivePerl?

I just recently installed ActivePerl 5.12.2.1202 on my Windows XP in C:/Perl. I am new to Perl scripting.
I just want to run a Perl program which contains one print statement, which I saved in Notepad with the name ex.pl.
How can I run this Perl program?
Can I use an editor for typing a Perl script other than Notepad?
How do I use ActivePerl?
Run Perl program from command prompt
start->run>cmd (command prompt will appear), write perl full_path_of_your_script,
like
C:\> perl hello.pl #This assumes that perl is in your PATH environment variable.
There are many Perl Editors, you can
used for Perl scripts like DzSoft,
Perl Expess, Komodo Edit etc and also see http://www.perlmonks.org/?node_id=169668 and Perlfaq3- Windows Perl Editors for more detail.
Have a look at http://docs.activestate.com/activeperl/5.12/, for ActivePerl 5.12 documentation.
Perl programs (or any other program run by an interpreter) is run by passing the script as a command-line argument to the interpreter. For example, in this case:
perl.exe ex.pl
Padre the Perl IDE and Kephra are good editors for Perl.
As an alternative to ActivePerl, there is Strawberry Perl.
Perl programs are run using the Perl interpreter, perl.exe.
This is normally done from the command line:
C:\>C:\Perl\bin\perl ex.pl
If perl.exe is in your PATH environment variable that can be shortened to:
C:\>perl ex.pl
If you opted to have *.pl files associated with Perl during installation, you can also double-click on them from Windows Explorer.
If you have *.pl files associated with Perl and add .PL to your PATHEXT environment variable you can run them like any other executable:
C:\>ex
Perl programs are just text files. They can be edited with any text editor (Padre, Kokomo, vim, emacs, Notepad++, etc.). Use whichever one you like best.
ActivePerl is just a distribution of Perl. "Using" it usually means running perl.exe to execute your program. ActivePerl also includes the PPM (Perl Package Manager) utility to make it easier to install modules from CPAN, particularly if you don't have a C compiler available. Most experienced Perl developers prefer to use the cpan shell.
Just to add to the other answers, I use EPIC, the Perl eclipse plugin. I'm using Perl on a Windows 7 64 bit machine.
I still run scripts off the command line in windows using ActivePerl, but for development I like being able to dynamically step through the script line by line.
just to not paraphrase other answers and to be more helpful (even if the post is somehow old ) i recommend using the switch "-e" to run Perl scripts if they are composed of few statements e.g
Perl -e "print('hello')"
and of course this requires that the Perl executable is in the Path variable,if not and assuming Perl is under the folder c:\Perl , you can add it by taping :
set %PATH%=%PATH%;c:\Perl\bin
when it comes to the choice of text editor ,I'm still using Notepad++ for almost everything ,it come with some useful features like keywords highlighting and some auto-completion capabilities.