Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Memorizing The s/// Option List For Fun and Profit

by tobyink (Abbot)
on May 23, 2013 at 15:02 UTC ( #1034962=note: print w/ replies, xml ) Need Help??


in reply to Memorizing The s/// Option List For Fun and Profit

Take a peek at the source code for B::Deparse, a module that takes an in-memory Perl optree and outputs a string of Perl source equivalent to it. Given the /g /i, /m and /r modifiers, it could easily output something like: s/foo/bar/gimr but instead, with typical Perl finesse, it will, if possible, rearrange the modifiers to form a word: s/foo/bar/grim.

The list of words it will try is repeated below...

my %matchwords; map($matchwords{join "", sort split //, $_} = $_, 'cig', 'cog', 'cos', + 'cogs', 'cox', 'go', 'is', 'ism', 'iso', 'mig', 'mix', 'osmic', 'ox', 'sic +', 'sig', 'six', 'smog', 'so', 'soc', 'sog', 'xi'); # ... my %substwords; map($substwords{join "", sort split //, $_} = $_, 'ego', 'egoism', 'em +', 'es', 'ex', 'exes', 'gee', 'go', 'goes', 'ie', 'ism', 'iso', 'me', 'meese', 'meso', 'mig', 'mix', 'os', 'ox', 'oxime', 'see', 'seem', 'seg', 'sex', 'sig', 'six', 'smog', 'sog', 'some', 'xi', 'rogue', 'sir', 'rise', 'smore', 'more', 'seer', 'rome', 'gore', 'grim', 'g +rime', 'or', 'rose', 'rosie');
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name


Comment on Re: Memorizing The s/// Option List For Fun and Profit
Select or Download Code
Replies are listed 'Best First'.
Re^2: Memorizing The s/// Option List For Fun and Profit
by QM (Vicar) on May 24, 2013 at 08:09 UTC
    I must say, I'm a bit disappointed ;) Leaving out obvious wins like "miracles" and "ideograms"?

    And I realize I forgot to try more e's. Heck, I suppose technically all of them can be repeated. Trying a bit harder and a bit looser, there's magicexposure, geodesicmap, supermelodic, and my favorite so far, maliciouspleasure.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

      Bear in mind that some regexp modifiers are mutually exclusive; for example /a which imposes ASCII semantics on the string being matches, and /l which imposes locale semantics on it. Thus s/foo/bar/miracles is a compile time error.

      Here's a quick script to find allowable words...

      #!/usr/bin/env perl use v5.18; open my $dict, "<", "/usr/share/dict/words"; while (<$dict>) { next unless /^[msixpodualgcer]+$/; chomp; my $ok = do { my $testing = $_; local $_; # protection eval "s/foo/bar/$testing; 1"; }; say if $ok; }

      I rather like these ones:

      • amigos
      • carcass
      • circus
      • corridor
      • crisscross
      • gigolo
      • girls
      • idiom
      • igloo
      • macrocosm
      • macroscopic
      • mammograms
      • microcosm
      • microscopic
      • orgasmic
      • pompous
      • program
      • sarcasm
      • scissors

      Now to find a way to patch B::Deparse...

      package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

        Now to find a way to patch B::Deparse..

        Patches should be submitted to perl5-porters@perl.org

        You can clone the repo with git clone perl5.git.perl.org:/perl

        ---
        $world=~s/war/peace/g

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1034962]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2015-07-07 22:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls