#!/usr/bin/perl -w use strict; my $format; while (<DATA>) { my $line = $_; # this line has alphbet, try to seperate if ($line =~ /[a-zA-Z\d]/) { LINE: while (1) { # (([\x81-\xfe][\x40-\xfe])*) greedy match on chinese. # line starts with chinese if ($line =~ /(([\x81-\xfe][\x40-\xfe])*)/ && $1) { my $e = $1; # update line $line = $'; $format .= ($line=~ /^\s/) ? $e : $e." "; } elsif ($line =~ /(.*?)([\x81-\xfe][\x40-\xfe])/) { # line starts with non-chinese chars my $e = $1; # the second match eats one chinese char, so get it ba +ck. $line = $2.$'; # add space after english char if it isn't ended with +space. $format .= ($e=~/\s$/) ? $e : $e." "; } else { $format .= $line; last LINE; } } } else { $format .= $line; } } print $format; __DATA__ 在 2004 年7月的开源大会时能比CPython更快的执行Python的字节码 “Perl现在生机勃勃 Perl 6被建议不应只作为Perl的新的实现 perl 5.8.x,仍然生机勃勃,Jarkko Hietaniemi今年的早些时候把 在2003年10月,发布了

In reply to format text which mixed english and chinese characters. by Qiang

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.