List Info

Thread: Re: Ascii to hexavalue and decimal




Re: Ascii to hexavalue and decimal
country flaguser name
United States
2007-09-17 07:21:13

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.chaturvediaptaracorp.com>
wrote:

>
>
>
>
> Perfect!!! I made few changes in it to get &#x000A9; sort of output.
>
> Thanks again.
&gt;
> On 9/17/07 5:01 PM, "Thiago Nascimento" < nascimenthiago%40gmail.com">nascimenthiagogmail.com
> <mailto:nascimenthiago%40gmail.com> > wrote:
&gt;
>>; >
>>; >
>>; >
>>; >
>>; > Try this code:
&gt;> >
>>; > #!/usr/bin/perl
>;> >
>>; > use warnings;
>> > use strict;
>> >
>>; > my $char = '(c)';
&gt;> > my $decval = ord $char;
&gt;> > my $hexval = sprintf(&quot;%x";, $decval);
>> >
>>; > print "$char in hex is $hexval and in dec is $decval&quot;;
>> >
>>; > HTH.
>;> >
>>; > On 9/17/07, pank_chat245 < pankaj.chaturvedi%40aptaracorp.com">pankaj.chaturvediaptaracorp.com
&gt;> <mailto:pankaj.chaturvedi%40aptaracorp.com>
>> > <mailto:pankaj.chaturvedi%40aptaracorp.com> > wrote:
&gt;>>> >> >
>;>>&gt; >> > Hi everybody,
>>>> >> >
>;>>&gt; >> > Can somebody throw some light why my code is not working.
>>&gt;> >> >
>;>>&gt; >> > All I am trying to covert ascii character in to their corresponding
hexa
>>&gt;> >> > value and to decimal
>>>;> >> > values too.
>;>>&gt; >> >
>;>>&gt; >> > I am working on Mac OS X
>&gt;>> >> >
>;>>&gt; >> > #!/usr/bin/perl
>;>>&gt; >> >
>;>>&gt; >> > $char = (c);
>;>>&gt; >> > $hexval = sprintf(&quot;%x";, $char);
>>>;> >> > $decval = hex($hexval);
>>>>; >> >
>;>>&gt; >> > print "$char in hex is $hexval and in dec is $decvaln&quot;;
>;>>&gt; >> >
>;>>&gt; >> > Thanks for suggestiona.
>&gt;>> >> >
>;>>&gt; >> > Pankaj
&gt;>>> >> >
>;>>&gt; >> >
>>;>> >> >
>;
> [Non-text portions of this message have been removed]
>
>
>

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
DB v.s File??
country flaguser name
United States
2007-09-17 10:09:24

At what point does it save time and processer usage between
reading and writing the entire file and using a database?

How big does a file have to be before its faster to use a DataBase like
mySql?

given todays computer speeds can a file that is only 40K really make a
difference.

Yes.. I know I >SHOULD< use a DB.. .but I can't find a book that has the
code
in simple, plain perl (as opposed to perl that is written for people with
PhD's in Programming)
I just do this as a hobby..
Thanks for any help
Lou

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )