Therefore one idea that strikes me is to manually set the contents of $ARGV[n] at the top of the source before any other code is run. Would this approach work?

Sure, that's fine, just make sure to only set it when you're running under the debugger, so as to not override any command line options later set by the user. There isn't really anything that magical about @ARGV, most functions and modules only read it at runtime, and you can write to it whenever you like. If in theory you had a module that accessed @ARGV when you use it, you'd need to set it in a BEGIN block before you use that module, but I haven't come across a module that does this yet.

use Data::Dump; use Getopt::Long; @ARGV = qw/ --foo --bar=123 --quz=Hello /; GetOptions(\my %OPTS1, 'foo|f', 'bar|b=i', 'quz|q=s') or die; dd \%OPTS1; @ARGV = qw/ -q World /; GetOptions(\my %OPTS2, 'foo|f', 'bar|b=i', 'quz|q=s') or die; dd \%OPTS2; __END__ { bar => 123, foo => 1, quz => "Hello" } { quz => "World" }

In reply to Re: Embedding command-line arguments within source code by haukex
in thread Embedding command-line arguments within source code by morelenmir

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.