so I was testing some stuff I want to do in a large project.. I wanted my configuration files to contain perl's regeular expressions to allow the configs to be as flexible as possible.. so I threw together a nasty little test script (doesn't use strict or do any error checking) but basically proves that it can work and that its just pretty damn cool :)
test.pl
#!/usr/bin/perl
open(R, "file.r");
while(<R>) {
chomp;
push @REG,$_;
}
open(I, "file.i");
while(<I>) {
chomp;
foreach $regex (@REG) {
if(/$regex/) {
print "$_ matched $regex\n";
for $i (1..5) {
if($$i) {
print "\t\$$i: $$i\n";
}
else { last; }
}
}
}
}
file.r:
^a
interface (POS(\S*))
fun
file.i:
interface POS5/7
a dog
a
ant eats stuff.
b
stuff
yields:
interface POS5/7 matched interface (POS(\S*))
$1: POS5/7
$2: 5/7
a dog matched ^a
a matched ^a
ant eats stuff. matched ^a
Perhaps I'm a just easy to impress, but does anyone else see the beauty and power of this? :)
its those little revelations that make life more fun :)
anyone else have any "little things" that have made their life infinitely more fun?
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.