...

View Full Version : Escaping Special Characters-Help



aniwebapp
04-20-2009, 08:36 PM
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.

bazz
04-20-2009, 11:31 PM
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

KevinADC
04-21-2009, 08:14 AM
If the other perl script is out of your control there is nothing you can do.

aniwebapp
04-21-2009, 08:58 AM
$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;

KevinADC
04-21-2009, 06:04 PM
$pwd =~ s/([list-of-special-characters-in-here])/\\$1/g;

aniwebapp
04-22-2009, 08:12 AM
Thanks gr8 help :-)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum