http://qs321.pair.com?node_id=920783

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

Greetings Monks!

I've got a weird problem. I have a script that is losing two args from ARGV before the script finished compiling.

My best guess is that one of my own modules is shifting ARGV in a BEGIN block, but I cannot find it.

By putting lots of BEGIN { print join(', ',@ARGV)."\n" } blocks in there and in modules it loads I've narrowed it down somewhat.

The heavy lifting for this script is in a module I'm writing. Before I use my module, ARGV is fine. After I use it, ARGV is two items shorter. I put more of my ARGV printers in my module and ARGV is fine at the top of the file all the way to the bottom.

So, it looks like something is happening after the compiler finishes reading my module and before it gets back to reading the script that usees the module. Does anyone know what that might be?

Because I'm pretty sure that made no sense, I'll try to illustrate with an example:

Module.pm

package Module; BEGIN { print 'beginning my module'.join(', ',@ARGV)."\n" } # do lots of stuff BEGIN { print 'ending my module'.join(', ',@ARGV)."\n" } 1;

script.pl

#! /usr/bin/perl -w -T BEGIN: { print 'before using my module'.join(', ',@ARGV)."\n" } use lib qw(.); use Module; BEGIN { print 'after using my module'.join(', ',@ARGV)."\n" }

Run it...

# ./script.pl three two one before using my module three, two, one beginning my module three, two, one ending my module three, two, one after using my module one

Note this is not what you see if you run my example code. This is what you get if you run my actual code. My actual code is too huge an embarrasing to post.

Woah!I just ran my example code and the results look like:

$ ./script.pl beginning my module ending my module after using my module before using my module

Which means my understanding of how this stuff is ordered is truly whacked...

A BEGIN block is supposed to execute as soon as the compiler finishes reading it, right? How does the order from my example script come about then?

Hopefully this post includes enough rambling to alert the many of you who are smarter than me to a plausable error. I'm going to stop typing now.

Thanks!

--Pileofrogs

P.S. I am not crazy