2

Consider this simple perl program:

#!/usr/bin/perl -s
print "ARGV: @ARGV\n";
print "arg: $arg\n";

Now run it:

chmod u+x test.pl
./test.pl -arg=works

The output is:

ARGV: 
arg: works

Running the program in the debugger works, too:

perl -d test.pl -arg=works

Loading DB routines from perl5db.pl version 1.53
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(./test.pl:3):    print $arg, "\n";
  DB<1> c
ARGV:      <-- SEE HERE
arg: works <-- SEE HERE
Debugged program terminated.  Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
  DB<1> q

However the argument will no longer be parsed if an include path is added:

perl -I . -d test.pl -arg works

Loading DB routines from perl5db.pl version 1.53
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(./test.pl:3):    print $arg, "\n";
  DB<1> c
ARGV: test.pl -arg=works <-- OOPS
arg:                     <-- OOPS
Debugged program terminated.  Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
  DB<1> q

When -I is used @ARGV does not seem to processed the same way. It is like the -s option no longer works as it is supposed to consume switches like -opt=value. Why is that?

Getopt::Long and Getopt::std both work just fine in all cases.

I thought for some time Perl extension in Visual Studio Code did not work correctly.

1
  • I can duplicate this behavior with perl -I . -d test.pl -arg works, but not with perl -I. -d test.pl -arg works (Note the lack of space between the -I and its argument). Odd. Commented Aug 8, 2021 at 4:49

1 Answer 1

1

I can confirm that this is a bug. Reported.


Your test cases were quite poor, having lots of unnecessary and un-eliminated variables. So I'm going to do my own testing:

#!/usr/bin/perl -s
print "ARGV: @ARGV\n";
print "arg: $arg\n";
print @ARGV == 0 && $arg eq "test" ? "ok\n" : "XXX\n";
# Baseline
$ perl a.pl -arg=test
ARGV:
arg: test
ok

# With -I .
$ perl -I . a.pl -arg=test
ARGV: a.pl -arg=test
arg:
XXX

# The problem isn't the use of both -I and -s.
$ perl -I . -s a.pl -arg=test
ARGV:
arg: test
ok

# What about -w?
$ perl -w a.pl -arg=test
ARGV:
arg: test
ok

# Or -0?
$ perl -0777 a.pl -arg=test
ARGV:
arg: test
ok

# It's just -I
$ perl -CSDA a.pl -arg=test
ARGV:
arg: test
ok

$ perl -v | grep This
This is perl 5, version 34, subversion 0 (v5.34.0) built for x86_64-linux-thread-multi

This is a workaround:

$ perl -Mlib=. a.pl -arg=test
ARGV:
arg: test
ok
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.