One of my colleagues wrote a perl script that asks for the user's windows domain/user name, which of course we enter the the following format domainname\username
. The Getopt:Long module then converts this into a string dropping out the '\' character and rendering the string incorrect. Of course, we could just ask all our users to enter their domain/user combo as domainname\\username
but I really don't want to be guilty "fix the user, not the programme". We also use a module we made for this, I'll call OurCompany::ColdFusionAPI
since it accesses ColdFusion.
Our code looks like this:
#!/usr/bin/perl
use common::sense;
use Getopt::Long;
use OurCompany::ColdFusionAPI;
my ($server_ip, $username, $password, $need_help);
GetOptions (
"ip|server-address=s" => \$server_ip,
"user-name=s" => \$username,
"password=s" => \$password,
"h|help" => \$need_help,
);
$username ||= shift;
$password ||= shift;
$server_ip ||= shift;
if (!$server_ip or $need_help){
print_help();
exit 0;
}
my $print_hash = sub { my $a = shift; say "$_\t=> $a->{$_}" foreach keys %$a; };
...
If I add the line say $username
then it just gives the string without the '\'. How can I get perl to keep the '\'? Something along the lines of read -r
in bash.