Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Problem using -I argument with Perl

by rinceWind (Monsignor)
on Jan 10, 2007 at 16:56 UTC ( [id://593949]=note: print w/replies, xml ) Need Help??


in reply to Problem using -I argument with Perl

As imp has said, the -I option is a feature of the parsing of the command line, when the command is "perl". Unfortunately, you don't get the ability to jack in such command line options to perl, when you are using a file type association for .pl type files.

You can get some command line options by passing them in on the shebang (#!) line:

#!perl -wT

Not sure if this would work with -I on Windows: try it. If this doesn't work, there are two other approaches that will definitely work: set PERL5LIB=C:\perl-programs\modules (semicolon separated list of paths on Windows) or add a use lib into the script.

--

Oh Lord, won’t you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, won’t you burn me a Knoppix CD ?
(Missquoting Janis Joplin)

Replies are listed 'Best First'.
Re^2: Problem using -I argument with Perl
by ikegami (Patriarch) on Jan 10, 2007 at 17:41 UTC
    In Windows, Perl checks the shebang line for options.
    >type script.pl #!perl -Imoo $,=", "; $\="\n"; print @INC; >perl script.pl r:/Utils/perl/lib, r:/Utils/perl/site/lib, ., moo

    -I... adds to the end @INC.
    -Mlib=... adds to the front of @INC. (better)

Re^2: Problem using -I argument with Perl
by merrymonk (Hermit) on Jan 10, 2007 at 17:31 UTC
    Many thanks for the two replies.
    I favoured the use lib option and tried to use this so that the code became.
    use strict "vars"; my $inc_item; use lib "C:\\perl-programs\\modules"; foreach $inc_item (@INC) { print "$inc_item\n"; }
    This worked as required and gave the following from the print
    C:\perl-programs\modules
    C:/perl5/lib
    C:/perl5/site/lib
    .
    I then tried to use a moudule in the new directory with a new line at the end of the code above of
    use modules::test-module
    However, this did not worked as I then got the following
    Can't locate modules/test.pm in @INC (@INC contains: C:\perl-programs\modules C:
    /perl5/lib C:/perl5/site/lib .) at C:\perl-programs\test-inc-iarg.pz line 13.
    BEGIN failed--compilation aborted at C:\perl-programs\test-inc-iarg.pz line 13.

    It seems that the lines are not processed in order so that it 'got' to the
    use modules::test-module
    before the use lib line even though this nearer the beginning.
    How can this be made to work?

      Name your module with an underscore instead of a hyphen

      --

      Oh Lord, won’t you burn me a Knoppix CD ?
      My friends all rate Windows, I must disagree.
      Your powers of persuasion will set them all free,
      So oh Lord, won’t you burn me a Knoppix CD ?
      (Missquoting Janis Joplin)

        That did it! Many thanks.
        I would never have guessed that was the problem.
        However, I do not understand why the print output in the main part came after the print from the module when the code lines were the other way around.
      With the line
      use modules::test-module;
      you are trying to use

      C:\perl-programs\modules\modules\test-module.pm

      I suspect you mean to use

      C:\perl-programs\modules\test-module.pm

      For that, the correct syntax is:
      use test-module;
      because you directory C:\perl-programs\modules is already in the INC path.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://593949]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-18 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found