Thanks for all of the help on this so far...I took the suggestions and I expanded the sample program to see if that makes a difference...
I am hoping to get this as data driven as possible to reduce errors (especially when I cut-n-paste ;-)
I am looking to process some lines in a file and validate text (I am not yet using Taint, but will at some point ;)
My problem is how to validate \n or \t, as sometimes it is allowed in the text field.
The following code should work, but I just want to make sure that the s/\\t/\t/g; (and the other ones that I might need) are the best way to go)
Thanks again for any help!!!!
$PRE = '\[\s*';
$VALID1 = '[-a-zA-Z0-9_.* \t\n]';
$VALID2 = '[-a-z0-9_.*\n]';
$VALID3 = '[a-zA-Z]';
$VALID4 = '[-a-zA-Z0-9]';
$PST = '\s*\]';
while (<DATA>)
{
s/\\n/\n/g; #Are these harmless if
s/\\t/\t/g; #not needed???
print "yep\n" if m/$PRE($VALID1+)$PST
$PRE($VALID2+)$PST
$PRE($VALID3+)$PST
$PRE($VALID4+)$PST
/ox;
}
__DATA__
[TEST \n DATA] [ TEST DATA ] [ 2345423 ] [ TEST DATA ]\n
[TEST \n DATA] [ TEST DATA ] [ 2345423 ] [ TEST\tDATA ]\n
[TEST \n DATA] [ TEST DATA ] [ 2345423 ] [ TEST DATA ]\n
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.