ActivePerl and -P option

Discussion in 'Perl Misc' started by Viviana Vc, Jun 3, 2005.

  1. Viviana Vc

    Viviana Vc Guest

    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
    Viviana Vc, Jun 3, 2005
    #1
    1. Advertising

  2. 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
    Josef Moellers, Jun 3, 2005
    #2
    1. Advertising

  3. Viviana Vc

    Viviana Vc Guest

    On Fri, 03 Jun 2005 12:59:30 +0200, Josef Moellers
    <> 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
    Viviana Vc, Jun 3, 2005
    #3
  4. Viviana Vc <> 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
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jun 3, 2005
    #4
  5. Viviana Vc

    Sisyphus Guest

    "Viviana Vc" <> wrote in message
    news:...
    > 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
    Sisyphus, Jun 3, 2005
    #5
  6. 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.
    Christopher Nehren, Jun 3, 2005
    #6
  7. Viviana Vc

    Viviana Vc Guest

    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 <>
    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
    Viviana Vc, Jun 8, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Skybuck Flying

    Make and ActivePerl

    Skybuck Flying, Dec 7, 2004, in forum: Perl
    Replies:
    3
    Views:
    2,980
  2. Jason Cochran

    SQL Server 2000 DTS and ActivePerl

    Jason Cochran, Dec 2, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    353
    Jason Cochran
    Dec 2, 2003
  3. Julien ROUZIERES

    g++ -pg option and -shared option

    Julien ROUZIERES, Dec 21, 2004, in forum: C++
    Replies:
    1
    Views:
    716
    GianGuz
    Dec 21, 2004
  4. Robin

    activeperl + -T option

    Robin, Apr 20, 2004, in forum: Perl Misc
    Replies:
    10
    Views:
    267
    Robin
    Apr 24, 2004
  5. Ted
    Replies:
    7
    Views:
    552
    Sisyphus
    Dec 16, 2006
Loading...

Share This Page