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

Re: [FWP] 4 Consecutive Letters



>>>>> "RJK" == Ronald J Kimball <rjk@linguist.dartmouth.edu> writes:
  [In explanation of
    perl -ne'@a=a..z;for$i(0..22){print,last if/@a[$i..$i+3]/x}'
  ]
RJK> /@a[$i..$i+3]/ interpolates @a[$i..$i+3] as join($", @a[$i..$i+3]),
RJK> resulting in a regex like /a b c d/.  But we need a regex like /abcd/.
RJK> One solution would be to set $" to '', but a shorter solution is to use
RJK> /x, which tells Perl to ignore the whitespace in the regex.

Duh. I want to apologize for such a stupid question. I'm not _quite_
as much of an idiot as I appear. :-} I knew what the /x modifier does,
but somehow got to thinking it was doing more than just ignoring
whitespace in Ronald's examples even after removing some of the
obfuscation.

As a small amount of redemption I present the solution I had come up
with before Ronald beat me out with his entries. Mine's not as short,
ironically uses the /x modifier, and is quite similar to, yet less
ingenious than, Ilmari's. But there you go...

  perl -ne'@a=a..z;print if/@{[join"|",map"@a[$_..$_+3]",0..22]}/x'

Hope you have a very nice day, :-)
Tim Ayers (tayers@bridge.com)
Norman, Oklahoma where I probably should heed the advice
"It is better to remain silent and thought a fool, than to speak up
and remove all doubt."


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