PhilHibbs has asked for the wisdom of the Perl Monks concerning the following question:

I sent a colleague a perl script, wrapped in my standard Perl polyglot, and named with a .cmd extension, so that it can easily be run from the Windows command line. This is the wrapper I use, which is based on bat2pl from the ActiveState Perl installation:
@rem = '--*-Perl-*-- @echo off perl "%~dpnx0" %* goto endofperl @rem '; #!perl #line 8 use strict; use warnings; # perl code goes here __END__ :endofperl
This runs as a batch, and line 3 calls perl with the batch file's full drive, path, name, and extension (that's the %~dpnx0) as the first parameter, and then all other parameters appended after.

She reported back to me that after installing ActiveState Perl 5.8.1.807, she gets the following error:

Name "main::rem" used only once: possible typo at E:/.../csvsplit.cmd +line 1.
I experimented on my machine, and I could make it do this by putting -w in the perl statement on line 3, and then fix it again by putting -wx in, so I advised her to put -x in the call thus:
perl -x "%~dpnx0" %*
Any ideas why her installation gives this error, and mine (same ActiveState version) doesn't?

Replies are listed 'Best First'.
Re: Perl Polyglot Problem
by PodMaster (Abbot) on Mar 09, 2005 at 13:00 UTC
    Any ideas why her installation gives this error, and mine (same ActiveState version) doesn't?
    Your copy of warnings is broken and hers is working? Try to test it.

    update: Also, you should contact perl5-porters about adding %~dpnx0 to pl2bat instead of just -S %0

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Your copy of warnings is broken and hers is working? Try to test it.
      The first line (@rem=...)is executed with warnings not turned on, warnings only get turned on when the compiler gets past the use warnings; statement. It seems that her installation has warnings turned on by default.
      Also, you should contact perl5-porters about adding %~dpnx0 to pl2bat instead of just -S %0
      %0 is appropriate for .bat files, because that works on Windows 95 et al. Only Windows NT and descendants support the %~ syntax, but I am confident that my scripts won't need to run on Windows 95/98/Me.
        It seems that her installation has warnings turned on by default.
        Wasn't that apparent before? I doubt the actual installation has warnings on by default. She's probably invoking csvsplit.cmd directly with perl (perl -w csvsplit.cmd) or she has a a perl.bat in her path which invokes perl.exe -w or something silly like that ...
        %0 is appropriate for .bat files, because that works on Windows 95 et al. Only Windows NT and descendants support the %~ syntax
        pl2bat already differentiates between 9x and NT, so the users of NT should have the benefit of not searching %PATH% again :)

        MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
        I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
        ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Perl Polyglot Problem
by Mugatu (Monk) on Mar 09, 2005 at 18:54 UTC
    I realize this doesn't answer your question (PodMaster seems to be doing a good job of that), but you might want to take a look at PAR for distribution of scripts. It will let you compile a standalone executable with everything the script needs to run included inside. HTH