Hi Thiago,
Well I¹ve another question related to this, instead of defining $char as
(c)¹ or any other special character, can I do something like any symbol or
special character (as I am not sure which special character can I have in my
file).
Let me try to be more clear, all I am trying to search and replace all the
special characters in an xml to their corresponding Unicode hex value.
Earlier I was trying to it like:
!#usr/bin/perl -w
open (IN, "$ARGV[0]");
undef $/;
$_=<IN>;
$file=$_;
if ($file=~m/©/g)
{
$file=~s/©/
/g;
}
elsif ($file=~m/®/g)
{
$file=~s/®/®/g;
}
open (OUT,">$ARGV[0]");
print OUT $file;
close(OUT);
close(IN);
But in the above case I need to define all special characters in my if
condition and then replace it to their hen values, which seems to be too
lengthy and least desirable.
I am new in Perl and tried my hands to write a script which I posted
earlier, but again I do not know how to say/define in perl ³convert any
special character into its hex value in a file².
Apologies for asking so much but any suggestions in this regar will be
highly appreciated.
Thanks
On 9/17/07 5:20 PM, "Pankaj Chaturvedi" < pankaj.chaturvedi%40aptaracorp.com">pankaj.chaturvedi
aptaracorp.com>
wrote:
>
>
>
>
> Perfect!!! I made few changes in it to get © sort of output.
>
> Thanks again.
>
> On 9/17/07 5:01 PM, "Thiago Nascimento" < nascimenthiago%40gmail.com">nascimenthiago
gmail.com
> <mailto:nascimenthiago%40gmail.com> > wrote:
>
>> >
>> >
>> >
>> >
>> > Try this code:
>> >
>> > #!/usr/bin/perl
>> >
>> > use warnings;
>> > use strict;
>> >
>> > my $char = '(c)';
>> > my $decval = ord $char;
>> > my $hexval = sprintf("%x", $decval);
>> >
>> > print "$char in hex is $hexval and in dec is $decval";
>> >
>> > HTH.
>> >
>> > On 9/17/07, pank_chat245 < pankaj.chaturvedi%40aptaracorp.com">pankaj.chaturvedi
aptaracorp.com
>> <mailto:pankaj.chaturvedi%40aptaracorp.com>
>> > <mailto:pankaj.chaturvedi%40aptaracorp.com> > wrote:
>>>> >> >
>>>> >> > Hi everybody,
>>>> >> >
>>>> >> > Can somebody throw some light why my code is not working.
>>>> >> >
>>>> >> > All I am trying to covert ascii character in to their corresponding
hexa
>>>> >> > value and to decimal
>>>> >> > values too.
>>>> >> >
>>>> >> > I am working on Mac OS X
>>>> >> >
>>>> >> > #!/usr/bin/perl
>>>> >> >
>>>> >> > $char = (c);
>>>> >> > $hexval = sprintf("%x", $char);
>>>> >> > $decval = hex($hexval);
>>>> >> >
>>>> >> > print "$char in hex is $hexval and in dec is $decvaln";
>>>> >> >
>>>> >> > Thanks for suggestiona.
>>>> >> >
>>>> >> > Pankaj
>>>> >> >
>>>> >> >
>>>> >> >
>
> [Non-text portions of this message have been removed]
>
>
>
[Non-text portions of this message have been removed]
.