in reply to Passing Array to Function for search and Replace

checkCurrency($hardwareValue1, $hardwareValue2); sub checkCurrency{ for (@_) { if ($currency eq "Euro (EUR)") { s/€//g; }elsif ($currency eq "Japan, Yen(JPY)") { s/Â/ /g; }elsif ($currency eq "United Kingdom, Pound(GBP)") { s/Â/ /g; } } }

Of course, the real problem is that you're not using Encode's decode to translate UTF-8 bytes into characters, and later Encode's encode to translate the characters into the proper encoding (or Encode's from_to to do it in one step).

Replies are listed 'Best First'.
Re^2: Passing Array to Function for search and Replace
by ikkon (Monk) on Jan 08, 2007 at 18:42 UTC
    I have been trying to looking into the Encode, but was never sucessful, it would not print anything when I tried, since i have to get this working today, I didn't have alot of time to figure it out I spent a few hours on it but still couldn't wrap my mind around it.

      Say you want to convert from UTF-8 to iso-latin-1,

      use Encode qw( decode encode ); ... input ... foreach ($hardwareValue1, $hardwareValue2) { $_ = decode('UTF-8', $_); } ... do some work ... foreach ($hardwareValue1, $hardwareValue2) { $_ = encode('iso-latin-1', $_); } ... output ...

      If you just want to translate,

      use Encode qw( from_to ); ... input ... foreach ($hardwareValue1, $hardwareValue2) { $_ = from_to($_, 'UTF-8', 'iso-latin-1'); } ... output ...

      If a given char doesn't exist in iso-latin-1, you'll get a ? instead.

      Remember, when you read in something, it is encoded. Convert it to characters before working on it. When you need to write something, it needs to be encoded.