baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:

hi,

my problem is that i'm trying to do something that is not meant to be done. i,m using Getopt::Long module in my script and need to pass a string into the script from a shell/cmd , something like:

./prog.pl -o function(key => './path')
function(key => './path')-> is a string that i'm trying to pass

and program(prog.pl) looks like:

#!/usr/bin/perl use strict; use Getopt::Long; my $option; GetOptions('o=s' =>\$option); eval($option); sub function { my %arg = @_; ... }
the problem is, if i do not put an option in ' ' or " " to define it as a string of some sort, i get an error:
-bash: syntax error near unexpected token `('
but if my variable or a key is in the quotes like in the example then it is an error for me again if i put ' ' or " ". how to override this problem does anyone have any idea.

thnx

Update:

i neglected to mention:

i know that if a user uses " " around a string "function(key => './path')" it will work, but the user shouldn't care about anything except the way to properly write its string. and what if a user writes it like: "function(key => "./path")"

Replies are listed 'Best First'.
Re: Getopt::Long problem
by moritz (Cardinal) on Jun 24, 2009 at 20:55 UTC
    ./prog.pl -o "function(key => './path')"

    works for me, in the bash.

Re: Getopt::Long problem
by zwon (Abbot) on Jun 24, 2009 at 21:33 UTC

    It's not Getopt::Long problem. That's how bash parses command line. '(' has some special meaning for bash, and also it uses spaces to separate arguments, so you can't avoid quoting.

Re: Getopt::Long problem
by graff (Chancellor) on Jun 25, 2009 at 01:36 UTC
    You say:

    i know that if a user uses " " around a string "function(key => './path')" it will work, but the user shouldn't care about anything except the way to properly write its string.

    If the user "shouldn't care about anything except" the exact typing of the string, then the user should not be using the shell command line to do this.

    Provide some other input method -- not a shell command parameter -- for the user to supply this complicated string; e.g. read it from a file or from stdin/pipeline, or put up a quick/easy Tk window with a text entry widget, and get the string without it having to pass through the shell's command-line interpreter.