Connecting Tech Pros Worldwide Forums | Help | Site Map

Need help in escaping the character "#" from the url

Member
 
Join Date: Jan 2007
Posts: 55
#1: Oct 16 '07
Dear All,

I am facing a problem in escaping the character "#" from the url. I am working in Mason framework now which uses Perl, HTML and Javascript.

What I really want is to escape the character "#" from the value assigned to a variable. As this value gets appended to the url, I am not getting the correct and expected values.

Eg: Suppose $value = "My#Group";

Here I want to escape the character # so that the variable $value contains the value "My#Group" instead of "My" as Perl considers the character # as the starting of comments and comments whatever is there after that.

Moreover the value of this variable gets appended to the previously existing url and as Perl treats # as commenting character, it is not considering the values after # in the url.

I have used URI::Escape::uri_escape() and HTML::Entities::encode_entities() methods but not able to get the solution.

Please help me in this.

Thanks in advance.

eWish's Avatar
Moderator
 
Join Date: Jul 2007
Location: Arkansas
Posts: 900
#2: Oct 16 '07

re: Need help in escaping the character "#" from the url


If I understand you correctly, you want to be able to include the '#" symbol in a variable.

Expand|Select|Wrap|Line Numbers
  1. my $test_val  = qq{Some#Name};
  2. my $test_val1 = q{Some#Name};
  3. my $test_val2 = 'Some#Name';
  4. my $test_val3 = "Some#Name";
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#3: Oct 17 '07

re: Need help in escaping the character "#" from the url


The # symbol is not considered a comment in the context it's being used. There should be no problem to have a # symbol in a URL.
Member
 
Join Date: Jan 2007
Posts: 55
#4: Oct 17 '07

re: Need help in escaping the character "#" from the url


Quote:

Originally Posted by KevinADC

The # symbol is not considered a comment in the context it's being used. There should be no problem to have a # symbol in a URL.


Dear Kevin

When I tried to copy the url in the address bar and pasted it in an editor, the text which is after the character # in the url appears to be commented when the file view is Perl.

Eg; In EditPlus, if the file view type is perl and I pasted the url in the editor, the text after # appears to be commented.
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#5: Oct 17 '07

re: Need help in escaping the character "#" from the url


Well, thats an editor. It may depend on how you view it in the editor, but a # in a single or double-quoted string is just a literal #, it is not a comment.

Expand|Select|Wrap|Line Numbers
  1. # this a comment
  2. $foo = "# this is not a comment";
Member
 
Join Date: Jan 2007
Posts: 55
#6: Oct 17 '07

re: Need help in escaping the character "#" from the url


Quote:

Originally Posted by KevinADC

Well, thats an editor. It may depend on how you view it in the editor, but a # in a single or double-quoted string is just a literal #, it is not a comment.

Expand|Select|Wrap|Line Numbers
  1. # this a comment
  2. $foo = "# this is not a comment";


Thanks for the reply.
Reply


Similar Perl bytes