ActivePerl and -P option

V

Viviana Vc

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 (http://www.activestate.com/)

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
compilation".

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 a.pl 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,
Viv
 
J

Josef Moellers

Viviana said:
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 (http://www.activestate.com/)

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
compilation".

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 a.pl line 1."

That's what perldoc perlrun says.
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,

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

If you read on, it says
'Because
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
 
V

Viviana Vc

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

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
error.
If you read on, it says
'Because
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.
Nope.


# 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?

No. There is sed for windows
(http://gnuwin32.sourceforge.net/packages/sed.htm), I installed it, it's
in the path, but still the same error :(
My 2cts,

Josef

Thx,
Viv
 
T

Tad McClellan

Viviana Vc said:
I am new to these lists,


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.

I have to write a perl script that uses some defines from an .h file.
those defines (i.e. #define ALFA "alfa") I


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? :)

have to run the script through the preprocessor first,


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;/;
 
S

Sisyphus

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
error.

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
cases.

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

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

D:\pscrpt>perl -P try.pl
7

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 Config.pm, but that's about as far as I've got ....
any ideas on how to proceed ?

Cheers,
Rob
 
C

Christopher Nehren

I have to run the script through the preprocessor first, and the help
^^^^^^^^

You mean the POD, yes? "help" to me implies a proprietary, compressed(?)
format accessible via a Microsoft program or software that emulates
such.
says this is supported: "-P run program through C preprocessor
before compilation".

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
apply.

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

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 a.pl line 1."

This is expressly documented in the POD as not doing what you expect.
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?

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
 
V

Viviana Vc

Thanks for your answers.

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

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

Thanks,
Viv
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top