Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Following up on the remark to look up unicode support in Perl, you'll need to know the name of the character encoding used in your data. IIRC, "Traditional Chinese" would refer to some sort of "Big5" encoding, but there might be more than one sort of "Big5", and the difference might matter. (My Perl 5.8.1 on macosx/panther supports "big5-eten" and and "big5-hkscs"; there might also be a "CP???" version.)

Whatever character set is appropriate, it might be easiest to save a plain text file containing just the "CHT string" (or both the preceding and the following "CHT string", if these are not identical), in the same character set as the original data. Then something like this should do:

use strict; use Encode; open( I, "string.txt" ); my $string = <I>; chomp $string; # or: my ($pre,$fol) = split ' ',$string; # if file has previous and following strings close I; my $pattern = decode( 'big5-eten', $string ); # you might need a different character-set name (if so, fix it in thre +e places) # also, if you are using $pre and $fol, you need to decode each one se +parately # (e.g. into $pat1 and $pat2) my $newversion = "2.0"; # or whatever... open( I, "<:encoding(big5-eten)", "big_data.txt" ); binmode( STDOUT, ":encoding(big5-eten" ); while ( <I> ) { s/($pattern).*?($pattern)/$1$newversion$2/; # or: s/($pat1).*?($pat2)/$1$newversion$2/; # maybe you also need the "g" modifier too? print; }
(not tested, of course, but nothing much to it, really)

In reply to Re: Regex for Multibyte Characters by graff
in thread Regex for Multibyte Characters by Anonymous Monk

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-28 18:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found