LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-18-2006, 03:02 PM   #1
rigel_kent
Member
 
Registered: Nov 2004
Posts: 64

Rep: Reputation: 15
Exclamation Unescape in Perl


Hi there,

I made a function in Perl to unescape escaped characters (like in JavaScript). BUT, the strings are imported from a input txt file.

Example: escape this

Code:
%2Ebu%74to%6E%3D%3D%32%29|%7C%28e%76en%74%2Eb%75tt%6Fn%3D%3D3%29%29%7Br%65tu%72n

gives

.button==2)

and it should have given

.button==2)||(event.button==3)){return
I use my routine:

Code:
sub UNESCAPE { 
    my($todecode) = @_; 
    $todecode =~ tr/+/ /;
    $todecode =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; 
    return $todecode; 
}
Everything was well until the "|" show up. The function only unescapes until the "|" (and probably until special characters). If we put the sequence between "" it works. But if we fetch it by input, everything goes wrong...

How can I solve this?

Rigel_Kent
 
Old 05-18-2006, 04:46 PM   #2
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
Quote:
Originally Posted by rigel_kent
Everything was well until the "|" show up. The function only unescapes until the "|" (and probably until special characters). If we put the sequence between "" it works. But if we fetch it by input, everything goes wrong...
So your function works. I'm not sure what you mean by "if we fetch it by input, everything goes wrong..."? Can you show the complete code of what you are trying to do when it doesn't work?

Last edited by spooon; 05-18-2006 at 04:47 PM.
 
Old 05-18-2006, 06:15 PM   #3
rigel_kent
Member
 
Registered: Nov 2004
Posts: 64

Original Poster
Rep: Reputation: 15
Ok,

We have a text file with the following sequence, for example (the first line):

Code:
blah1blah2%2Ebu%74to%6E%3D%3D%32%29|%7C%28e%76en%74%2Eb%75tt%6Fn%3D%3D3%29%29%7Br%65tublah3blah4blah5
We then:

Code:
open (FILE,"<teste.txt");
@data = <FILE>;
foreach $line(@data){
$results = $line =~ m/blah2(.*?)blah3/gi;
if ($1){
print UNESCAPE($1);
}
}
close FILE;
Rigel_Kent
 
Old 05-18-2006, 07:17 PM   #4
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
Quote:
Originally Posted by rigel_kent
Ok,

We have a text file with the following sequence, for example (the first line):

Code:
blah1blah2%2Ebu%74to%6E%3D%3D%32%29|%7C%28e%76en%74%2Eb%75tt%6Fn%3D%3D3%29%29%7Br%65tublah3blah4blah5
We then:

Code:
open (FILE,"<teste.txt");
@data = <FILE>;
foreach $line(@data){
$results = $line =~ m/blah2(.*?)blah3/gi;
if ($1){
print UNESCAPE($1);
}
}
close FILE;
Rigel_Kent
Works fine for me. It prints ".button==2)||(event.button==3)){retu" as it should. You should probably print a newline at the end so the prompt starts on a new line.
 
Old 05-19-2006, 01:33 AM   #5
rigel_kent
Member
 
Registered: Nov 2004
Posts: 64

Original Poster
Rep: Reputation: 15
Quote:
You should probably print a newline at the end so the prompt starts on a new line.
Still doesn't work for me. What do you mean with the new line?

Regards,

Rigel_Kent
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with perl module for w3c validator to work on my local Apache+PHP+perl instal tbamt Linux - Software 0 12-16-2004 05:37 PM
cgi perl : I cant get perl to append my html file... the_y_man Programming 3 03-22-2004 05:07 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
chrooting apache v2 (php, ssl, perl support) ; perl configuration markus1982 Linux - Security 3 01-26-2003 06:15 PM
can i set ~/public_html/perl as a perl directory for apache? doublefailure Linux - Networking 1 07-09-2002 04:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration