ActivePerl and -P option

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hi all,

I am new to perl, so I am new to these lists, but I hope I am posting in
the right groups.

I have installed on my Win 2k system the latest version of ActivePerl
5.8.6 ( /)

I have to write a perl script that uses some defines from an .h file. So
I decided to include in the perl script that .h file (i.e. #include
"a.h"), but in order to use those defines (i.e. #define ALFA "alfa") I
have to run the script through the preprocessor first, and the help says
this is supported: "-P   run program through C preprocessor before

I tried this in 2 ways, and failed both ways:

1) I tried at the beginning of the perl script to put:
#!/usr/bin/perl -P
but by running the script I get:
"Can't emulate -P on #! line at line 1."

2) By running the perl with -P option I always get "The system cannot
find the path specified.". Any clue why do I get this error? Any clue
how could I fix this?

Any help would be most appreciated,

Re: ActivePerl and -P option

Quoted text here. Click to load it

This is not a "list" (as in "email list").

This is a "newsgroup", which is a very different thing.

Anyway, there are Posting Guidelines posted here twice a week that
contains lots of tips and tricks to increase your chances of
getting answers.

Quoted text here. Click to load it

Surely you must have mean "e.g" instead of "i.e".

Don't you want to handle defines with names and values that
are different from the one you've shown?  :-)

Quoted text here. Click to load it

You don't "have" to, there are other ways.

Like converting your C defines into Perl constants. See

   perldoc constant

Then you can just convert them into Perl with something like:

   s/^#define\s+(\w+)\s+(.+)/use constant $1 => $2;/;

    Tad McClellan                          SGML consulting                   Perl programming
    Fort Worth, Texas

Re: ActivePerl and -P option

Viviana Vc wrote:
Quoted text here. Click to load it

That's what perldoc perlrun says.

Quoted text here. Click to load it

I assume your include file contains valid perl code, otherwise it won't
work anyway.

If you read on, it says
             both comments and cpp directives begin with the #
             character, you should avoid starting comments with
             any words recognized by the C preprocessor such as
             "if", "else", or "define".'

Maybe you have a comment which starts with 'include', e.g.

# include whatever files necessary

Also, it says
                       It requires not only a working C preproces­
                       sor but also a working sed.  If not on
                       UNIX, you are probably out of luck on this.

Maybe it's looking for sed?

My 2cts,

Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
                        -- T.  Pratchett

Re: ActivePerl and -P option

On Fri, 03 Jun 2005 12:59:30 +0200, Josef Moellers

Quoted text here. Click to load it

My include file contains just some defines like:
#define ALFA "alfa"

But, I get the "The system cannot find the path specified" error by just
typing in cmd prompt "perl -P", without having any perl script or
include files. So it's not related to those but with other files that
perl needs. If I am giving the wrong or right files I get the exact same

Quoted text here. Click to load it


No. There is sed for windows
( ), I installed it, it's
in the path, but still the same error :(

Quoted text here. Click to load it


Re: ActivePerl and -P option

Quoted text here. Click to load it

Yes, I get the same with perl 5.8.4 (ActiveState build 810), though MSVC++
6.0 is locatable.
With the same version of perl, but built with MSVC++ 7.0 (.NET), I get a
slightly more explanatory message:

'F:\perlvc7\bin' is not recognized as an internal or external command,
operable program or batch file.

'F:\perlvc7\bin' is the perl\bin folder (containing perl.exe, etc.) - I
don't know why such a command is being run.

With my MinGW-built perl 5.8.6 (a slightly newer version of perl), I find
there is no problem. The '-P' switch works as intended, at least in simple

---- try.h ----
#define ALSA 7

---- ----
use warnings;
#include "try.h"
print ALSA, "\n";

D:\pscrpt>perl -P

So - it's not a Win32 issue, but looks to be some issue with the Microsoft
compiler/preprocessor. I have verified that the 'F:\perlvc7\bin' command is
not related to the contents of the 'path' environment variable, and that
it's not being read from, but that's about as far as I've got ....
any ideas on how to proceed ?


Re: ActivePerl and -P option

On 2005-06-03, Viviana Vc scribbled these
curious markings:
Quoted text here. Click to load it

You mean the POD, yes? "help" to me implies a proprietary, compressed(?)
format accessible via a Microsoft program or software that emulates

Quoted text here. Click to load it

It also says this, at least on my FreeBSD system:

<begin quote>
-P   NOTE: Use of -P is strongly discouraged because of its inherent
           problems, including poor portability.


If you're considering using "-P", you might also want to look at
the Filter::cpp module from CPAN.


The problems of -P include, but are not limited to:

*         The "#!" line is stripped, so any switches there don't

*         A "-P" on a "#!" line doesn't work.

<end quote>

Quoted text here. Click to load it

This is expressly documented in the POD as not doing what you expect.

Quoted text here. Click to load it

Maybe try Filter::cpp, which I presume is more portable? Before cringing
at the fact that it's in the Filter namespace, remember that cpp itself
is one of the oldest and most venerable of filters in existence. :)

Best Regards,
Christopher Nehren
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated". -- Ken Thompson
If you ask the wrong people questions, you get "Joel on Software".
Unix is user friendly. However, it isn't idiot friendly.

Re: ActivePerl and -P option

Thanks for your answers.

In the end I chose to do as a prerun-step:
cl /EP >
where cl is the compiler of VC 7.1 that I have installed on my system,
and then run the

Seems everything works as expected like this, so for now I'll stay with
this solution.


wrote :

Quoted text here. Click to load it

Site Timeline