Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert multiple Unicode in a string to character
    text
    copied!<p>Problem -- I have a string, say <code>Buna$002C_TexasBuna$002C_Texas</code>' and where <code>$</code> is followed by Unicode. I want to replace these Unicode with its respective Unicode character representation.</p> <p>In <a href="http://en.wikipedia.org/wiki/Perl" rel="nofollow">Perl</a> if any Unicode is in the form of "<code>\x{002C}</code> then it will be converted to it respective Unicode character. Below is the sample code.</p> <pre><code>#!/usr/bin/perl my $string = "Hello \x{263A}!\n"; @arr= split //,$string; print "@arr"; </code></pre> <p>I am processing a file which contain 10 million of records. So I have these strings in a scalar variable. To do the same as above I am substituting <code>$4_digit_unicode</code> to <code>\x{4_digit_unicode}</code> as below.</p> <pre><code>$str = 'Buna$002C_TexasBuna$002C_Texas'; $str =~s/\$(.{4})/\\x\{$1\}/g; $str = "$str" </code></pre> <p>It gives me</p> <pre><code>Buna\x{002C}_TexasBuna\x{002C}_Texas </code></pre> <p>It is because at <code>$str = "$str"</code>, line <code>$str</code> is being interpolated, but not its value. So <code>\x{002C}</code> is not being interpolated by Perl.</p> <p>Is there a way to force Perl so that it will also interpolate the contents of <code>$str</code> too?</p> <p>OR</p> <p>Is there another method to achieve this? I do not want to take out each of the Unicodes then pack it using <code>pack "U4",0x002C</code> and then substitute it back. But something in one line (like the below unsuccessful attempt) is OK.</p> <pre><code>$str =~ s/\$(.{4})/pack("U4",$1)/g; </code></pre> <p>I know the above is wrong; but can I do something like above?</p> <p>For the input string <code>$str = 'Buna$002C_TexasBuna$002C_Texas'</code>, the desired output is <code>Buna,_TexasBuna,_Texas</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload