Getopt ::长时间将带空格的字符串放入变量 [英] Getopt::Long getting a string with spaces into a variable

查看:249
本文介绍了Getopt ::长时间将带空格的字符串放入变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个使用Getopt :: Long解析命令行参数的perl脚本.但是,我有一个参数可以接受字符串(带空格).我怎样才能把整个字符串变成一个变量.例如:

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

我需要变量$ string中的等等等等".我知道Getopt :: Long支持一个参数的多个输入,当您知道有多少个时(我不知道).这可能吗?

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?

推荐答案

您需要在参数周围加上引号:

You need to either put quotes around the argument:

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

或逃脱空格:

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

这篇关于Getopt ::长时间将带空格的字符串放入变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆