in reply to Re: Escape variables
in thread Escape variables

Below is the portion of my code relevant to the issue I am having, its a script to login to another system via ssh
my $username; my $password; print "Please enter username to connect to the system:" ; chomp($username=<>); print "Please enter password\n"; chomp($password=<>);

Replies are listed 'Best First'.
Re^3: Escape variables
by Marshall (Canon) on Jan 06, 2016 at 07:50 UTC
    I think you you are getting what you want, but your printout statement is misleading you?

    #!usr/bin/perl use strict; my $in = 'r;OFTaf#a2Mt9d\1'; #single quote is literal quote #this is what your input should get print $in, "\n"; #print $in "as is", not within quotes =prints r;OFTaf#a2Mt9d\1
Re^3: Escape variables
by afoken (Chancellor) on Jan 06, 2016 at 18:09 UTC
    a script to login to another system via ssh

    Don't mess with passwords, use public key authentication. See PuTTY FAQ "Remember Password" and Using public keys for SSH authentication. (Note that using public key authentication is not PuTTY specific, it's a basic feature of SSH.)

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re^3: Escape variables
by Marshall (Canon) on Jan 06, 2016 at 07:30 UTC
    I have some quibbles about how you accept input. In a standard command line I/F leading or trailing spaces should not matter. But this looks to me like it should "work". How are you printing $password?
Re^3: Escape variables
by Marshall (Canon) on Jan 09, 2016 at 11:18 UTC
    I don't know what the rest of your code does.
    Code like this should get the input token and strip out the leading and trailing white-space.
    #/usr/bin/perl use warnings; use strict; my $username; print "Please enter username to connect to the system:" ; $username=<>; $username =~ s/^\s+//; #trim leading whitespace $username =~ s/\s+$//; #trim trailing whitespace #this includes \r, \n, etc. print $username, "\n";