in reply to Comparing Lines within a Word List
OTOH, if you're looking for words that contain a particular pair of characters, and differ only in terms of using one vs. the other of those two (e.g. you really just want "bare/base", etc., but not "foot/fool"), you would probably want to use a regex like this:
(update: fixed the "while" condition as per hippo's remark below -- also added anchors around $regex in the grep call, so that "bare" doesn't match "debased", etc.)#!/usr/bin/perl use strict; use warnings; my @words = <DATA>; chomp @words; while ( @words >= 2 ) { my $model = my $regex = shift @words; if ( $regex =~ s/(.*?)[rs](.*?)/$1\[rs\]$2/ ) { my @hits = grep /^$regex$/, @words; if ( @hits ) { print join( " ", $model, "matches", @hits, "using", $regex +, "\n" ); } } } __DATA__ bare mare base case bust burt bent sat rat bat matter mattes pat
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Comparing Lines within a Word List
by hippo (Archbishop) on Apr 27, 2016 at 08:53 UTC | |
Re^2: Comparing Lines within a Word List
by dominick_t (Acolyte) on Apr 27, 2016 at 03:57 UTC | |
by graff (Chancellor) on Apr 27, 2016 at 10:07 UTC | |
by dominick_t (Acolyte) on Apr 27, 2016 at 14:58 UTC | |
Re^2: Comparing Lines within a Word List
by Anonymous Monk on Apr 27, 2016 at 15:22 UTC | |
Re^2: Comparing Lines within a Word List
by dominick_t (Acolyte) on Apr 27, 2016 at 15:33 UTC | |
Re^2: Comparing Lines within a Word List
by dominick_t (Acolyte) on Apr 29, 2016 at 23:04 UTC | |
by hippo (Archbishop) on Apr 30, 2016 at 10:04 UTC | |
by dominick_t (Acolyte) on Apr 30, 2016 at 14:06 UTC | |
by graff (Chancellor) on Apr 30, 2016 at 15:27 UTC | |
by hippo (Archbishop) on Apr 30, 2016 at 14:26 UTC | |
by dominick_t (Acolyte) on Apr 30, 2016 at 14:49 UTC | |
|