Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jan 2009
    Posts
    34
    Thanks
    4
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    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

  • #3
    Senior Coder
    Join Date
    Mar 2006
    Posts
    1,274
    Thanks
    2
    Thanked 39 Times in 38 Posts
    If the other perl script is out of your control there is nothing you can do.

  • #4
    New Coder
    Join Date
    Jan 2009
    Posts
    34
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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;

  • #5
    Senior Coder
    Join Date
    Mar 2006
    Posts
    1,274
    Thanks
    2
    Thanked 39 Times in 38 Posts
    Code:
    $pwd =~ s/([list-of-special-characters-in-here])/\\$1/g;

  • Users who have thanked KevinADC for this post:

    aniwebapp (04-22-2009)

  • #6
    New Coder
    Join Date
    Jan 2009
    Posts
    34
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks gr8 help :-)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •