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

I am using 'Getopt::Long'.

Is there a way for script to go on if user's input contains '!' ?
user input ---> ./scriptname -a sdf!sdf -b gwerwer what i want to do ==> If I see ! in input, I want to just do /(.+)!.+/ and capture just $1

Replies are listed 'Best First'.
Re: how to ignore regex in input to getopt::Long
by perl_fan (Novice) on Jun 28, 2010 at 08:18 UTC
    Couple of things 1. you have to escape the exclamation mark in the command line i.e.  ./scriptname -a sdf\!sdf -b gwerwer 2. following is the code to capture $1 and $2, assuming that you are capturing the value in switch a (-a) in $data
    if($data =~ m/(.+)?\!(.+)/) { print "first: $1 , next:$2 \n"; }
      Hi, thanks for replying.
      However, I am trying to have it so that people do not have to escape anything on command line.. is this not possible due to shell interpretation before perl?
        It depends on your OS/shell. In unix-type shells, ! must be escaped because of its special meaning as a command history/substitution character. I just verified this on 3 shells: sh, bash and tcsh.

        However, at a Windows DOS prompt, it is not necessary to escape the !.

        Then don't use a character that has a special meaning for many popular shells. What about ":"?
Re: how to ignore regex in input to getopt::Long
by Anonymous Monk on Jun 28, 2010 at 08:17 UTC
    Getopt::Long and show some code example to see how you tried implemented that...