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


In reply to debugging during compile by pileofrogs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.