Michael Higgins wrote:
> Allegakoen, Justin Devanandan wrote:
> 
>>Peter,
>>
>>I was playing around with this earlier. Heres what I get:-
>>
>>Microsoft Windows XP [Version 5.1.2600]
>>(C) Copyright 1985-2001 Microsoft Corp.
>>
>>C:\Perl\Programs>perl -e "print ord('£');"
>>163
>>C:\Perl\Programs>perl -e "print chr(163);"
>>ú
>>C:\Perl\Programs>perl
>>for(150..170)
>>{
>>        print "$_ = " , chr($_) , "\n";
>>}
>>^D
>>150 = û
>>151 = ù
>>152 = ÿ
>>153 = Ö
>>154 = Ü
>>155 = ¢
>>156 = £
>>157 = ¥
>>158 = ₧
>>159 = ƒ
>>160 = á
>>161 = í
>>162 = ó
>>163 = ú
>>164 = ñ
>>165 = Ñ
>>166 = ª
>>167 = º
>>168 = ¿
>>169 = ⌐
>>170 = ¬
>>
>>C:\Perl\Programs>perl -e "print chr(156);"
>>£
>>C:\Perl\Programs>
>>
>>
>>Is that right?
>>
>>Just in
>>
> 
> 
> Justin --
> 
> Yeah, that's exactly what I got hung up on... and then too hastily 
> posted my hangup. I'm glad you sussed out what I'm gettin' at.
> 
> I guess the char just gets translated when it prints to STDOUT -- as 
> printing to a file and opening in the same text editor seems to produce 
> the expected character.
> 
> Basically, I was grabbing a pound value, maybe like m/(£[\d,]+) and then 
> s/£/\$/ on a var givent the results of $1 -- and not getting the subs I 
> expected, or errors about unknown characters when I started tweaking it. 
> My 'googling' led me to think I'd have better results if I knew the hex 
> value... and I saw the phenomenon you posted. I finally just replaced 
> them using my text editor and fixed the numbers up with a script.
> 
> So, at one point, I'd concluded the problem lay with running the script 
> by shelling out from my text editor or maybe just within my code... but 
> why _does_ the char seem to get changed from 163 to 156?
> 
> Anyway, below is what I came up with, warts 'n all, to try to change a 
> price list from pounds to dollars, and it seems to work, perhaps because 
> I don't capture '£' and try to sub it in the result.
> 
> I have to imagine there's something already done to take care of this in 
> a more authoritative way, but I didn't find it quickly and it seemed it 
> should be easy. I was suprised to find it wasn't, and then, in looking 
> on the web, that other folks had apparently had similar problems, but no 
> posted suggestion I read helped me.
> 
> I see others just weighed in as well. Thanks to all!
> 
> -- mike higgins
> 
> 8<  - - - - - - - - -  8<  - - - - - - - -
> 
> $rate = 1.65;
> foreach my $line (<DATA>){
> $line =~ m/£([\d,]+)/;
> $price = $1;
> $price =~ s/,//g;
> $price = sprintf "%.2f",($price * $rate);
> $line =~ s/£[\d,]+/\$$price/;
> print $line;
> }

Or just put it all in a RE and substitute:

foreach ...
        $line =~ s/£([\d,]+)/{ my $tmp = $1; $tmp =~ s#,##g; $_ =
                  sprintf '$%.02f', $tmp * $rate }/e;
        print ...
}

or maybe more readable:

        $line =~ s#
                    £([\d,]+)
                  # {
                    my $tmp = $1;
                    $tmp =~ s/,//g;
                    sprintf '$%.02f', $tmp * $rate
                  }#ex;


> __DATA__
> Licence       £500
> User Licence  £250
>   Users*      £2,250
> Users £4,250
> live data only)       £6,900



-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (Free site for Perl/Lakers)


_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to