Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   ActivePerl and -P option (http://www.velocityreviews.com/forums/t892683-activeperl-and-p-option.html)

Viviana Vc 06-03-2005 10:04 AM

ActivePerl and -P option
 
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

Josef Moellers 06-03-2005 10:59 AM

Re: ActivePerl and -P option
 
Viviana Vc wrote:
> 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
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett


Viviana Vc 06-03-2005 12:09 PM

Re: ActivePerl and -P option
 
On Fri, 03 Jun 2005 12:59:30 +0200, Josef Moellers
<josef.moellers@fujitsu-siemens.com> wrote :

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

Tad McClellan 06-03-2005 01:42 PM

Re: ActivePerl and -P option
 
Viviana Vc <vcotirlea@hotmail.com> wrote:

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


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Sisyphus 06-03-2005 02:22 PM

Re: ActivePerl and -P option
 

"Viviana Vc" <vcotirlea@hotmail.com> wrote in message
news:3gavgeFbku9rU1@individual.net...
> On Fri, 03 Jun 2005 12:59:30 +0200, Josef Moellers


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



Christopher Nehren 06-03-2005 05:07 PM

Re: ActivePerl and -P option
 
On 2005-06-03, Viviana Vc scribbled these
curious markings:
> 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.

<end quote>

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

Viviana Vc 06-08-2005 08:06 AM

Re: ActivePerl and -P option
 
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

On Fri, 03 Jun 2005 12:04:40 +0200, Viviana Vc <vcotirlea@hotmail.com>
wrote :

>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




All times are GMT. The time now is 07:49 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.