And indeed your code doesn't work!
Yeah, I caught that a little late. As penance I tried to track down a hook, but couldn't find one. And so I offer up a solution using a guard. It's more intimidating, but at least it auto-expires and allows fine-grained localization.
use strict;
use warnings;
my $log = parse_regex( q#(\\.|["']|x)# );
print $log;
warn "And STDERR is back\n";
sub parse_regex {
my ($regex) = @_;
# Catch and stash warnings
my $guard = stderr_eater(my $parselog);
# --- compile regex
eval q{
use re 'debug';
qr/$regex/;
};
return $parselog;
}
sub stderr_eater {
package STDERR::Eater;
open my $guard, '>&', STDERR;
close STDERR;
open STDERR, ">", \$_[0];
return bless \$guard;
sub DESTROY {
close STDERR;
open STDERR, ">&", $_[0];
}
}
My first thought was YAPE::Regex. Actually my first thought was roll my own, but that's more of a reflection on my own poor choices. It looks like there's some reasonable robustness there, but was unsure if this fell into the "online analyzers which are easily fooled". It'll at least take care of the tokenizing for you.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|