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 who
While I certainly agree that you should escape the arguments, if like me you have situation where you don't easily have control over the input then it is actually possible to do this with Getopt::Long.
Example: [https://www.jdoodle.com/a/oHG]
use strict;
use Getopt::Long qw(GetOptions);
my @spaces_string;
GetOptions('test=s{1,}' => \@spaces_string);
printf "String is: '%s'\n" ,join " ",@spaces_string;
You are defining your option as having 1 or more values, assign it to an array and then join it back into a string.
This is explained quite well under the 'Options with multiple values' section of the documentation: http://perldoc.perl.org/Getopt/Long.html#Options-with-multiple-values