Search code examples
perlcommand-line-argumentsgetopt-long

Getopt::Long getting a string with spaces into a variable


I'm making a perl script which uses Getopt::Long to parse command line arguments. However, I have an argument which can accept a string (with spaces). How can I get the whole string into a variable. For example:

./script.pl --string=blah blah blah blah yup --another-opt

I need "blah blah blah blah yup" in variable $string. I know Getopt::Long supports multiple inputs for one argument when you know how many you will have (which I do not). Is this possible?


Solution

  • You need to either put quotes around the argument:

    ./script.pl --string="blah blah blah blah yup" --another-opt
    

    or escape the spaces:

    ./script.pl --string=blah\ blah\ blah\ blah\ yup --another-opt