Hello kind monks. I am writing a quick and dirty script to do array command line processing. I want it to be able to accept arguments in the form of:
args.pl FOO=BAR TEST=VISION EVERYTHING=TWO
I'm pleased to say that it works with this script:
my $defaults = {};
%defaults = map {(($_ =~ /([^\=]+)\=([^\s]+)/)?("$1" => "$2"):())} @AR
+GV;
print join(",", keys %defaults);
This is a build script for the curious. I do NOT want to use a module, because I'm not going to learn why this script isn't working, so I thank you, but please none of those suggestions. This is for theory at this point. Now, I want to add in the functionality to be able to take backslashed spaces off of the command line (as in a directory with spaces in it, or other sort of item, or anything else to make it more extensible). Like:
args.pl QUICK=BROWN\ FOX JUMPED=OVER\ THE\ LAZY DOG
Validly finding QUICK and JUMPED as keys, but ignoring DOG.
However, I can't seem to get it to work with the regular expression.
Boiling it down:
$_ =~ /([^\=]+)\=([^\s]+)/
is where this hell lies. The way I'm thinking of it, I see it as:
- At least one non equals characters, grouped
- An equals character
- At least one non-whitespace character, grouped
So, substituting this in a couple of ways:
$_ =~ /([^\=]+)\=([[^\s]|[\\\s]]+)/)
- At least one non equals characters, grouped
- An equals character
- At least one (non-whitespace or backslashed whitespace character), grouped
That didn't work
Neither did:
$_ =~ /([^\=]+)\=([^[[^\\]\s]]+)/
Same as above except the last is:
....
- At least one (non- (non-backslashed whitespace)), grouped
This has the disadvantage of possibly being outright wrong (matching two characters?), but it's something I gave a shot to. So before I take up the shotgun and going blasting into the night for answers, can someone point me in the right direction? Am I looking for simply getting my negations right, or I am looking for more powerful regular expression gear. Thanks a bunch.
--
jb
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.