How can I run a Perl script with ActivePerl? - perl

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.

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 )

Cannot run any Perl scripts on Windows 8.1

I installed Active Perl 5.20
and also Strawberry Perl 5.20 after uninstalling Active Perl.
In both cases, when I open cmd and type 'perl' I get:
Unknown Unicode option letter ':'.
This error also prevents all scripts from running on my Windows 8.1 installation.
I uninstalled Perl and did a fresh install and it still doesn't work.
Are there dependencies that I need to install?
I googled the error but the results pertain to Linux installations where the script specified something wrong. But I get this error when I even try to use any perl command line or script. So my problem is not a faulty script.
That is the error message you get from using an invalid value for the -C command-line option. At a guess I'd say you have the PERL_UNICODE environment variable set to a string that contains a colon :.
Take a look at Command Switches in perldoc perlrun for more detail on this.
I too had this problem on windows 8.1 . The problem is that, once on installation, .pl files are not automatically recognized by Perl engine. So please select a .pl file and right click and say open with and set the default program to C\perl\bin\ inside it click perl.exe and recognize it. Once this is done your perl works flawlessly.

Is it possible with Padre to run and debug Perl scripts with a different Perl version?

Padre is a (open) IDE for Perl that does look promising.
Since Padre is written in Perl itself, it is not apparent whether it's easily possible and practicable to run and debug Perl scripts in this IDE that are running on a different Perl version than the IDE itself.
As an example, say I download the current installer (for Windows) which will install and run Padre on Strawberry Perl 5.12 -- can I then use this IDE to run+debug my scripts that are running on ActiveState Perl 5.8.9? (Yes, and I want them to run exactly on AS+5.8.9 because this is where they'll run in production.)
I am aware that there is a Padre package for AS+5.8.9 but I would much rather install the default IDE package and have the IDE run on the Perl it normally runs on and have my scripts run on the Perl they normally run on.
Insights?
Under Tools->Preferences->Language - Perl 5 you can specify the perl binary as well as its parameters to run your projects.

Can we use MinGW to compile a Perl script?

I have some problems to compile or run a Perl script in Windows. I have installed MinGW in my Windows to compile C code using the GCC package. Now, can I use MinGW to compile Perl script/code and how?
No. GCC does not include Perl. Try Strawberry Perl or ActivePerl for Windows which are Perl distributions for Windows.
See PAR::Packer's frontend pp, or "Cava Packager", or IndigoStar's Perl2Exe, or ActiveState's PerlApp
ActivePerl creates shortcuts for .pl files (if you check the box during installation). You can see the association by running the following from a prompt:
>assoc .pl
.pl=Perl
>ftype Perl
Perl="C:\Progs\perl5121-ap1201\bin\perl.exe" "%1" %*
(Use wahtever assoc returned as the argument for ftype.)
You can do it yourself with:
assoc .pl=Perl
ftype Perl=Perl="C:\Progs\perl5121-ap1201\bin\perl.exe" "%1" %*
(Use the correct path for your machine.)
Keep in mind that many scripts require command line inputs, and that the console closes down as soon as the script exits when you launch it from double-clicking. As such, it's often better to run your script from the prompt.
If you have the association setup as above, you can run a Perl script from the console simply by typing its name
>script.pl
Hello, World!
Or you can be explicit and specify that it requires Perl.
>perl script.pl
Hello, World!
That assumes that Perl is in the PATH. If not, you can specify the whole path to Perl.
>C:\Progs\perl5121-ap1201\bin\perl script.pl
Hello, World!

How can I make Eclipse work with `perlbrew`?

I'm using perlbrew to switch between perl versions. I also use Eclipse to write perl scripts.
It seems that Eclipse does not recognize the switches between perl versions, and keeps working with the base version installed out of perlbrew. I tried restarting Eclipse but this doen't help.
So, How can I make Eclipse work with perlbrew?
If you are using EPIC, this will work: Click through to Window->Preferences->Perl EPIC and set the Perl executable to perl5/perlbrew/bin/perl. This always points to the current set version of perl. The path is relative to your $HOME on Linux.
I haven't tried this as I usually just use a text editor for Perl, but I have taken to using the shebang line #!/usr/bin/env perl so that I get the perl for the user that runs the script (ie. perlbrew if me, system perl if root). If Eclipse executes the script (./myscript.pl) this should work, if instead it callsperl myscript.pl` then this will not help you.