Can we use MinGW to compile a Perl script? - perl

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!

Related

How to run file in strawberry perl portable 5.10.0.1 with arguments?

screen image here
Hi can someone tell me how to run a perl program with arguments in strawberry perl portable?
The problem is that before we were using DZsoft where there is an icon "run in command prompt" in "arguments:"we typed input file and output file and log name, and the perl pre-processor does the rest and creates the files in the same dir.
But in strawberry perl portable it must be done in cmd with commands that i don't know?
Can someone help with this?
Thanks
the Answer is
perl 4666513.pp(name of program) INVO_0423.xml(name of file) INVO_0423.out log.txt
very simple indeed...

How can I automate a Perl installation / script

I'm brand new to Perl. We have a useful script in the office that people would like to use. Unfortunately it has been deemed hard to setup because one has to download and install Strawberry Perl, manually install a few CPAN modules from the command line, and then run the script with the right arguments. It's really not that bad and there is a readme to follow but is there an easier way to handle the installation? I'm sure I could make a batch file to install the CPAN modules, but what about setting up the environment variables (if needed)? I don't suppose there is a way to automate the Strawberry Perl installation or have it 'come with' the necessary modules?
How would you normally install software on client workstations? That's the method you should use now.
If you don't have anything like that, I would suggest using psexec http://technet.microsoft.com/en-gb/sysinternals/bb897553.aspx
You should be able to 'silent install' Strawberry Perl with the MSI installer.
http://msdn.microsoft.com/en-us/library/aa372024%28v=vs.85%29.aspx
Then use psexec again, to do the CPAN installs.
If you need to do environment variables, then you can either do that within your perl script, or you might have to mess with the Windows registry remotely.
Create a BAT or CMD script that runs the Perl installer, followed by the CPAN install commands. The trick is probably that when the BAT starts, the Perl install area (C:\Perl\bin or whatever) won't be on the search PATH. That will make it hard to run the CPAN commands. So, the BAT script should include a command to manually add the path to CPAN into the script's environment. You can even build up a list of modules, and run them in a loop. I use ActiveState, not Strawberry Perl, but my installer looks like:
#echo off
Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegQry% > "%TEMP%\checkOS.txt"
Find /i "x86" < "%TEMP%\CheckOS.txt"
If %ERRORLEVEL% == 0 (
echo This is 32-bit operating system...
\\Server\Shares\Installers\ActivePerl-5.16.3.1603-MSWin32-x86-296746.msi
) ELSE (
echo This is 64-bit operating system...
\\Server\Shares\Installers\ActivePerl-5.16.3.1603-MSWin32-x64-296746.msi
)
REM Even though the above stuff should have installed Perl locally and updated the PATH,
REM the new PATH won't be available in this BAT script since it was launched before the change.
REM Add both possible locations for local Perl to the PATH before running the PPM commands below.
PATH=C:\Perl64\bin;C:\Perl\bin;%PATH%
set MODULE_LIST=(Archive-Extract DBI DBD-ODBC Data-Validate Date-Manip Date-Simple File-Copy-Recursive List-MoreUtils Mail-Sender Mail-Sendmail Params-Validate SOAP-Lite Spreadsheet-WriteExcel Text-CSV Tie-IxHash)
for %%i in %MODULE_LIST% do cmd/c ppm install %%i
Your final line would be a cpan command install of ppm, but hopefully you get the idea!

Setting the path to the interpreter in Emacs for Perl debugging with perldb

When I type M-x perldb to debug my Perl script, the debugging session fails, I think it is because I have a line at the beginning of my script that says:
use 5.010
The Emacs Perl debugger complains with:
Perl v5.10.0 required--this is only v5.8.6,
at /path/to/file
I think it's loading an old Perl interpreter (the default one installed in my system). However, I have a much newer interpreter installed on a different path, so how can I tell perldb in Emacs the path to the interpreter that I want it to use?
In a version of perldb.el I see this code:
(defvar perldb-command-name "perl"
"*Pathname of Perl interpreter.")
I'm sure if you either redefine the value of this variable, or if you set your PATH environment variable so that perl invokes the 5.10 version of perl, things will work for you.

Perl Packer not operating as expected

I've recently installed the Perl Packer module to compile my perl scripts into exe packages. I'm running strawberry perl setup on a windows 32-bit machine. When I attempt to run the pp -o command, I get an error stating that Perl is not part of my path. It is, for some reason, looking for perl in F:/Programs/Strawberry Perl/site/bin/perl.exe, when the true path is F:/Programs/Strawberry Perl/bin/perl.exe. Perl itself runs fine from commandline. How can I get Perl Packer to find my perl.exe?
What about calling this way?
perl pp {your options goes here}
regards

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.