Hi guys. The function of my program is to evaluate user provided patterns on user provided text - and then spit back the results. Of course, I've encountered a snag pretty early on.
Right now, I'm trying to get the -c flag working. I'm calling the script like this: regexTester -c /Bill Clinton/i, and I'm trying to evaluate the $text 'bill clinton'. It's failing! could you guys enlighten me as to why?
Here is the code (I've omitted the pod stuff to save space).
my %options=();
getopts('c:f:', \%options);
pod2usage(2) if (keys %options != 1);
if($options{c}){
#variable grab
my $pattern = qr/$options{c}/;
print "Please enter the text you wish to run the pattern on: ";
my $text = <STDIN>;
chomp $text;
#do work and display
if($text =~ $pattern){
print $&; #prints entire match
print " " . $text;
}
else{
print "$pattern on $text Failed. ";
}
}
Thanks monks. I know the problem probably lies in me not exactly understanding how qr// works.
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.