Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Updated: to comply with all the revised rules.

Here's cleaner version of the above that also deals with (all?) of the edge cases.

#! perl -slw use strict; sub uniq { my %x; @x{@_} = (); keys %x } my $len = shift @ARGV; my $re ; my $re_ex; my $cap = 1; my $cap_ex = 1; my $hints_uniq; for my $i ( 0 .. $#ARGV ) { my( $word, $common ) = split ':', $ARGV[ $i ]; my $uniq = join'', uniq( split '', $word ); $hints_uniq .= $uniq; if( $common <= length $word ) { $re_ex .= "\n\t(?= (?: .*? (?: [^$uniq] | (?: ([$uniq])(?= + .* \\" . $cap_ex++ . ") ) ) ){" . ( $len - $common ) . "} )" } if( $common >= 2 ) { $re .= "\n\t(?=.*?([$word]).*?(?!\\$cap)"; if( $common > 2 ) { my $base = $cap; for my $n ( 1 .. $common-2 ) { $re .= "([$word]).*?(?!" . join('|', map{ '\\' . $_ } $base .. ++$cap ) . ")"; } } $cap++; $re .= "[$word])"; } elsif( $common == 1 ) { $re .= "\n\t(?=.*[$word].*)" } } $hints_uniq = join '', uniq split'', $hints_uniq; my $re_covered = qr[^[$hints_uniq]+$]; $re = qr[^$re]x; $re_ex = qr[$re_ex]x; my %w; open W, '<', 'words' or die $!; m[^[a-z]+$] and push @{ $w{ length() } }, $_ while chomp( $_ = <W>||'' ); close W; my @m = grep{ $_ =~ $re_covered and $_ =~ $re_ex and $_ =~ $re } @{ $ +w{ $len } }; print ~~@m; print for @m;

Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.

In reply to Re^2: Challenge: Mystery Word Puzzle by BrowserUk
in thread Challenge: Mystery Word Puzzle by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (1)
As of 2024-04-18 23:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found