Go Back   CodingForums.com > :: Server side development > Perl/ CGI

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-20-2009, 07:36 PM   PM User | #1
aniwebapp
New Coder

 
Join Date: Jan 2009
Posts: 34
Thanks: 4
Thanked 0 Times in 0 Posts
aniwebapp is an unknown quantity at this point
Escaping Special Characters-Help

Hi All,

I am having a trouble in passing special characters to a script. As I am new to perl script I dont know how to go and solve this.

mypwd=(a+sdf!gh

if i pass $mypwd to another perl script, it is not accepting these special characters. It would be a great help if some one can help to escape these characters while passing to the script.

I have a perl script which escapes ";" like following.

$pwd =~ s/;/\\;/g;

But I want to modify it in a broader scale, ie it should escape whatever special character entered.
aniwebapp is offline   Reply With Quote
Old 04-20-2009, 10:31 PM   PM User | #2
bazz
Master Coder

 
Join Date: Apr 2003
Location: in my house
Posts: 5,211
Thanks: 39
Thanked 201 Times in 197 Posts
bazz will become famous soon enoughbazz will become famous soon enough
Is that declaration exactly how it is in your script?

it should be:-

my $pwd = '(a+sdf!gh';

to be technical, I should say that what you describe as 'escaping' is actually substitution though, in this case, the substitution was used to turn ; into \;

I'm not being picky. I think it's a good time to try to get into the way of differentiating between what something really is as opposed to what it is used for. what something is, is constant. but it may have many applications.

How are you trying to pass the variable to the second script? please post your code so we can get you a quicker response, with fewer questions.


bazz
__________________
"The day you stop learning is the day you become obsolete"! - my late Dad.

Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
Useful MySQL resource
Useful MySQL link
bazz is offline   Reply With Quote
Old 04-21-2009, 07:14 AM   PM User | #3
KevinADC
Senior Coder

 
Join Date: Mar 2006
Posts: 1,274
Thanks: 2
Thanked 39 Times in 38 Posts
KevinADC is on a distinguished road
If the other perl script is out of your control there is nothing you can do.
KevinADC is offline   Reply With Quote
Old 04-21-2009, 07:58 AM   PM User | #4
aniwebapp
New Coder

 
Join Date: Jan 2009
Posts: 34
Thanks: 4
Thanked 0 Times in 0 Posts
aniwebapp is an unknown quantity at this point
Code:
$dbh = DBI->connect($connectInfo,$userid,$passwd);

$update = "update ipm set approver=\'$ENV{REMOTE_USER}\' where username=\'$uname\'";
$sth = $dbh->prepare($update);
$sth->execute() or die $dbh->errmsg();

$query = "select * from ipm where username=\'$uname\'";
$sth = $dbh->prepare($query);
$sth->execute() or die $dbh->errmsg();

$sth->bind_columns(\$uname,\$pwd,\$environ,\$deposit,\$requestor,\$approver);
$sth->fetch();
$pwd =~ s/;/\\;/g; #here i want to modify it to accept other special characters
#print $pwd;
$cmd = "sudo ssh -i /root/.ssh/id_dsa server-fe '/var/www/scripts/sip_menu $uname $pwd $environ ${deposit}'";
#print $cmd;
$sth->finish();

print "Processing the request...";
print "<br><br><br><br><H2><center>";
$out = system("$cmd");
print "</center></H2>";

$query = "select * from email where user=\'$requestor\'";
$sth = $dbh->prepare($query);
$sth->execute() or die $dbh->errmsg();

$sth->bind_columns(\$user,\$mailid);
$sth->fetch();

$mail = system("./email.sh ".${uname}." ".${approver}." ".${mailid});

$sth->finish();
$dbh->disconnect;
aniwebapp is offline   Reply With Quote
Old 04-21-2009, 05:04 PM   PM User | #5
KevinADC
Senior Coder

 
Join Date: Mar 2006
Posts: 1,274
Thanks: 2
Thanked 39 Times in 38 Posts
KevinADC is on a distinguished road
Code:
$pwd =~ s/([list-of-special-characters-in-here])/\\$1/g;
KevinADC is offline   Reply With Quote
Users who have thanked KevinADC for this post:
aniwebapp (04-22-2009)
Old 04-22-2009, 07:12 AM   PM User | #6
aniwebapp
New Coder

 
Join Date: Jan 2009
Posts: 34
Thanks: 4
Thanked 0 Times in 0 Posts
aniwebapp is an unknown quantity at this point
Thanks gr8 help :-)
aniwebapp is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:48 PM.


Advertisement
Log in to turn off these ads.