I need to parse a string in the same manner as CLI arguments upon being passed to Getopt::Long. The string could have possible command line arguments that it gets by using a Read-Eval-Print-Loop program. Like say, this is my string:
$str = '--infile /tmp/infile_location --outfile /tmp/outfile'
Now, I need to have it parsed with GetOptions in order to have the scope for adding new options later.
I figured maybe splitting the string at its whitespaces and replacing @ARGV with new array could let me call GetOptions on it. So, here's how I've tried doing it so far:
my @arg_arr = split (/\s/, $input_line);
# This is done so that GetOptions reads these new arguments
@ARGV = @arg_arr;
print "ARGV is : @ARGV\n";
GetOptions (
'infile=s' => \$infile,
'outfile=s' => \$outfile
);
But this just seems like a workaround, is there a more direct approach or a better way to do it? Please Help!