views:

152

answers:

2

I wrote a Perl program "transfer.pl" and the input parameter is the hash value (the key and the value are strings). The code segment is:

my %transfers = ();

if (!GetOptions("transfer=s" => \%transfers))
{
    Usage();
    exit(1);
}

I used the windows system. On the command line, I typed:

perl tranfer.pl --transfer "table = %s"="[TableName=%s]"

I hope the key is table = %s and the value is [TableName=%s], but it seems Getopt::Long always finds the first = so the key is table and the value is %s=[TableName=%s].

When I typed

perl tranfer.pl --transfer "table \= %s"="[TableName\=%s]"

The key is table \, the value is %s=[TableName\=%s].

I want to know how to bypass the "=" in my string value and make the code do what I expect?

Thank you very much!

+1  A: 
Brad Gilbert
+2  A: 

Getopt::Long will not allow this; the first = is always used to separate the key from the value. You will need to use a user-defined subroutine to handle the option, or split up the key=value pairs after GetOptions is done or use some arbitrary escaping mechanism like using "%25" to represent a = in a key.

ysth