package importopt; use strict; my %type = (i => "^[+-]?[0-9]+\$", s => ".", f => "^[+-]?[0-9.]+(e[+-][0-9]+)?\$", v => "^\$"); sub import (@) { no strict 'refs'; shift (@_); my %arg = @_; if (!defined ($arg {options})) { return(); } my $ns = $arg {namespace} || ""; my %opt = %{$arg {options}}; my $args = \@{"$ns\::_args"}; my $err = \${"$ns\::_err"}; foreach my $o (keys (%opt)) { if ($opt{$o} =~ /^([a-zA-Z])(\[\])?$|^=(.*)/) { my ($t, $a, $r) = ($1 || "", $2 || "", $3 || ""); if ($r) { # option is an alias for another option unless ($opt{$r}) { print STDERR ("$o: reference to nonexistent option $r\n"); $$err = 3; } $opt{$o} = $opt{$r}; if (defined (@{"$ns\::$r"})) { *{"$ns\::$o"} = \@{"$ns\::$r"}; } else { *{"$ns\::$o"} = \${"$ns\::$r"}; } } else { # assigning twice to avoid "used only once" warning - p +erhaps not the cleanest solution if ($a) { @{"$ns\::$o"} = (); @{"$ns\::$o"} = (); } else { ${"$ns\::$o"} = ""; ${"$ns\::$o"} = ""; } $opt{$o} = $t; } } } @$args = (); $$err = 0; while (@ARGV) { if ($ARGV[0] =~ /^--?(.*?)(?:=(.*))?$/o) { my ($n, $v) = ($1, $2); if (defined ($opt{$n})) { if (($type{$opt{$n}}) && (($v || "") =~ /$type{$opt{$n}}/i)) { unless (defined ($v)) { $v = ""; } if (defined (${"$ns\::$n"})) { ${"$ns\::$n"} = $v; } else { push (@{"$ns\::$n"}, $v); } } else { print STDERR ("\"$v\": invalid value for $n ($opt{$n})\n"); $$err = 1; } } else { print STDERR ("$n: unknown option\n"); $$err = 2; } } else { push (@$args, $ARGV[0]); } shift (@ARGV); } @ARGV = @$args; } 1;

In reply to Getppt::(LongStd) replacement by Anonymous Monk

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.