我必须包含一个命令行开关(-r)来反向排序在命令行上通过@ARGV数组输入的字符串列表.我正在努力寻找一个关于命令行开关的好地方.我在网上找不到任何明确解释这些主题的好消息来源.
问题1:有没有人知道任何明确解释这个主题的好的在线资源?
我在网上找到了这个例子,但我无法让它工作.它将在命令行运行,并输出'hello,world',但如果我键入$perl -g filename.pl它将输出:无法识别的开关:-g(-h将显示有效选项).
问题2 为什么这不起作用?不应该用-g说'再见世界'吗?
#! /usr/local/bin/perl -s
use strict;
my( $switch, $thing );
$switch = shift;
if( $switch and $switch eq "-g" ) {
$thing = shift || 'world';
} else {
$thing = $switch || shift || 'world';
$switch = undef if $switch;
}
print $switch ? 'Goodbye' : 'Hello', ", $thing\n";
Run Code Online (Sandbox Code Playgroud) perl ×1