in reply to Specaila characters string not coming in final output file

Way too long.

If you're having trouble with usernames, trim it down to just that fragment. Throw that fragment into a test.pl, and print to see what it is doing with explicit inputs.


I did notice that you are removing only whitespace from the username. Specifically, you are not removing quote characters from the name.

Consider what happens if $User_Name = " joe's name here ";Then, your

$User_Name= "'" . $User_Name . "'";
Results in 'joe's name here' which has mismatched quotes.

In general, do not filter out bad characters. Instead, only allow good characters. That way if you miss one, you're not hosed.

$User_Name =~ s/[^a-zA-Z0-9]//g;
might be a better choice, or simply s/\D//g; if you want only numbers.

Replies are listed 'Best First'.
Re^2: Special characters string not coming in final output file
by namishtiwari (Acolyte) on Aug 07, 2009 at 15:24 UTC
    Thanks for the reply, but i do not have any exceptions in user name as you pointed out in joe example.Later i need to print those values in the file, if i take out the special characaters from the user name it will not have any meaning. So i need to do something within limitations. Is my apporaoch for special character handling is correct. Thanks NT

      SuicideJunkie is right - namishtiwari you need to cut down your code to something that makes the problem more clear and provide us with examples which clearly demonstrate 'expected' and 'unexpected' results, otherwise it is very hard to help you!

      And show us what you have tried! There are also many nodes here about dealing with special characters : SuperSearch.

      If you cannot enforce user name content, you might try escaping the characters s/([ special characters ])/\\$1/g ?

      Just a something something...
        Hi, I updated the piece of code and what is required only kept there and i also updated the thred with what is expected output and hat is coming. Thanks NT
        Hi MOnks, I have kept only code that is required and deleted rest from the thread. I pasted also what is required and what is coming here. Please give some code suggestions. Thanks NT