[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] 4 Consecutive Letters




On Mon, 14 Aug 2000, Ronald J Kimball wrote:
> /@a[$i..$i+3]/ interpolates @a[$i..$i+3] as join($", @a[$i..$i+3]),
> resulting in a regex like /a b c d/.  But we need a regex like /abcd/.
> One solution would be to set $" to '', but a shorter solution is to use
> /x, which tells Perl to ignore the whitespace in the regex.

D'oh!  Now that should've been obvious..

  perl -ne '/!@{[map+("|",a..z)[0,$_..$_+3],1..23]}/oix&&print'

And it seems the chr approach is even shorter:

  perl -ne '/!@{[map+("|",chr..chr$_+3),64..86]}/oix&&print'

Not as short as the $a++ solution, but these should work on older perls as
well.  Oh, and you can still save one stroke by dropping the "o", but the
speed will suffer.

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
"The screwdriver *is* the portable method."  -- Abigail in c.l.p.m



==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe