CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Split function returns weird characters

 



KingNothing
Novice

Jun 11, 2014, 8:13 AM

Post #1 of 6 (5542 views)
Split function returns weird characters Can't Post

Hi all,

I am facing a problem with a script I want to make. In short, I am connecting to a local database with dbi and execute some queries. While this works just fine, and as I print out the returned values from select queries and so on, when I split, say, the $firstName to an array and print out the array I get weird characters. Note that all the fields in the table I am working are containing only greek characters and are utf8_general_ci. I played around with use utf8, use encoding, binmode, encode etc but still the split function does return š weird characters while before the split the whole greek word was printed fine. I suppose this is due to some missing pragma about string encoding or something similar but really can't find out the solution. Thanks in advance
Here is the piece of code I am describing. Perl version is v5.14.2

™

Code
		@query = &DatabaseSubs::getStringFromDb(); 
print "$query[1]\n"; # prints the greek name fine
@chars = split('',$query[1]);
foreach $chr (@chars)
{
print "$chr \n"; # prints weird chars
}



Laurent_R
Veteran / Moderator

Jun 11, 2014, 11:57 AM

Post #2 of 6 (5387 views)
Re: [KingNothing] Split function returns weird characters [In reply to] Can't Post

Can you show the output, please?
Both for the first print and for the char by char printing?


KingNothing
Novice

Jun 12, 2014, 12:11 AM

Post #3 of 6 (5383 views)
Re: [Laurent_R] Split function returns weird characters [In reply to] Can't Post

Hello and thanks for your interest. Sure, here's the output from the terminal.
The first line is just fine while the others are created within the foreach loop.
Note that other weird characters may occur if I have in use pragmas like Encoding, utf8, and functions like binmode and encode/decode. The other weird characters are like squares with little numbers inside them.


(This post was edited by KingNothing on Jun 12, 2014, 12:12 AM)
Attachments: print.jpg (4.29 KB)


Laurent_R
Veteran / Moderator

Jun 12, 2014, 3:31 AM

Post #4 of 6 (5250 views)
Re: [KingNothing] Split function returns weird characters [In reply to] Can't Post

The problem with the word that you are using for your example is that it has only letters that are identical in the Greek and Latin alphabets, so that we don't really know if it would print correctly words with Greek letters that are not the same in the Latin alphabet. Did you try with other letters (i.e. with letters are are not similar in the latin alphabet) or with lower case letters?


KingNothing
Novice

Jun 12, 2014, 12:17 PM

Post #5 of 6 (5024 views)
Re: [Laurent_R] Split function returns weird characters [In reply to] Can't Post

Yes I did try with words having unique characters in greek alphabet and they are all printed well except from the foreach print. Also, I tried lowercase and had same results. I am really confused of what pragma and subs I should use to have the splitted characters printed right. Crazy


Laurent_R
Veteran / Moderator

Jun 12, 2014, 3:46 PM

Post #6 of 6 (4996 views)
Re: [KingNothing] Split function returns weird characters [In reply to] Can't Post

Well, I asked some questions to try to have you give more information which might be useful to someone else to give you an answer, but, to tell the truth, I know quite little on Unicode, UTF8, encode, etc., and I have never really understood how this whole shebang works. I am sorry, I can't help you further, I only hope that your answers to my questions might help someone more knoledgeable than me to help you.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives