Esteemed monks!
I have the following question for ye today: How can I define a list of regular expressions over which I subsequently want to iterate?
So far, I have tried the following, alas to no avail:
my @files = ( "File1", "File2", ... );
my @regexes = ( 'verb [\w<>]+\s+/', 'noun \w+\s+/', ... );
for my $file ( @files )
{
my $regex = qr/shift @regexes/;
...
$sizes{ $version }{ $file } ++ if /$regex/;
}
Syntax highlighting in my editor already informs me that this is syntactically unacceptable. I also tried various ways of quoting the entries in the list ... but none of them worked. The error message received is
Use of uninitialized value $regex in regexp compilation at ./compare.l
+exicons.pl line ...
Presumably, it is just a small thing I am overlooking -- but I simply cannot get it. Ideally, what I want is a list of compiled regular expressions that I can simply fetch using
shift and interpolate where needed. Your help in this matter hence would be much appreciated.
Thanks a lot in advance and best regards -
Pat
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.