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

[FWP] string evenness



>From a CLPM challenge/request, I give you this:

  $half = int(length($str)/2);
  $str =~ s{( ?)([^ ]*)(?<=^.{$half})([^ ]*)( ?)}
           { length($2) < length($3) ? "\n$2$3$4" : "$1$2$3\n" }e;

It turns the ' ' nearest the center of the string into a newline.  This is
used for making things like

  extraterrestrial space monkeys

into

  extraterrestrial
  space monkeys

-- 
Jeff "japhy" Pinyan     japhy@pobox.com    http://www.pobox.com/~japhy/
CPAN - #1 Perl Resource  (my id:  PINYAN)       http://search.cpan.org/
PerlMonks - An Online Perl Community          http://www.perlmonks.com/
The Perl Archive - Articles, Forums, etc.   http://www.perlarchive.com/


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