With a nod to Crackers2 above, who pointed out perl -MO=Deparse, here is a sort of " meta" program, which tries 'deparsing' ...
my $check = m/$mystrings[N]/;
... on incrementing values of N:
#! /usr/bin/perl -w
###############
## Libraries ##
###############
use strict;
use warnings;
use File::Basename;
use B::Deparse;
use IO::File;
#############
## Globals ##
#############
my $iam = basename $0;
$| = 1;
my $b_verbose = 0;
my $text = q{
use strict;
use warnings;
my @mystrings = ( "string" ) x 200;
my $check = m/$mystrings[<NUM>]/;
};
##################
## Main Program ##
##################
for (my $i = 0; $i <= 1000; $i++) {
try($i);
}
#################
## Subroutines ##
#################
sub try {
my ($n) = @_;
my $new = $text;
$new =~ s/<NUM>/$n/g;
my $fn = 'test.pl';
my $fh = new IO::File($fn, "w") or die "Can't write '$fn' ($!)\n";
print $fh "$new\n";
close $fh;
chomp(my @results = `perl -MO=Deparse $fn 2>&1`);
my ($check) = grep { /check/ } @results;
my $b_ok = ($check =~ /my \$check = \$mystrings\[\d+\]/)? 1: 0;
if ($b_verbose) {
printf "Value %4d => %s\n", $n, $b_ok? "Okay": "*** FAILS ***"
+;
} else {
printf "%s", $b_ok? '.': '@';
}
}
It prints '.' or '@' for "Okay" and "Failed" values of N, respectively.
You can also assign $b_verbose to a nonzero value to see more verbose results :)
s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
-
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.
|