Hello Monks;
I am in need of your wisdom.
The ultimate goal is ti create a method of validating user input. I have a script that prompts the user to enter values on the command line, (using getopts).
I have a configuration file (text file) where I have a line configured to store the 'allowed values'
Example:
Tags mail, page, conf, test
I am using use Config::Simple to read this file and create an array of "allowed" values:
open(FH, "config.txt");
$cfg->guess_syntax(\*FH));
my @tags = $cfg->param("Tags");
unlink $_ for @tags;
I then grab the user entry via getopts and store in an array
my @user_tags = $opt_c ;
And, I use use Array::Utils qw(:all) like so...
my @valid_tag = intersect(@user_tags, @hash_tags);
if (@valid_tag == 0){
die " \n\n NOTICE: TAG MISSING OR INVALID \n \
+n\n";
} else{
chomp (@valid_tag);
}
This works okay as long as only a single value is passed on the command line.
Example:
$ script.p, -c "test"
But, if I pass multiple values, the verification step fails
Example:
$ script.pl -c "test page"
NOTICE: TAG MISSING OR INVALID
Any advice would be much appreciated!
Thank you!
Bee
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.