When I run Perl scripts, I open up the Terminal window on my Mac and write "perl test1.pl
" after moving to the folder containing the Perl script.
Often I find myself wanting to run the same Perl many times, usually at the same time, but with very minor changes.
For example say this Perl script "test1.pl
" looks like this:
$year = 2001;
<rest of code that uses $year>
I want to execute "test1.pl" where $year = 2001, where $year = 2002, etc. To do this I usually run the script where $year = 2001, then adjust the script so $year = 2002, save, open new terminal window, run again, repeat.
Is there a way to submit the Perl script by designating in the terminal window the value for $year
?
私は次のようなことを考えています:
perl test1.pl, $year = 2001
これを行う1つの方法(多くの方法のうち)は次のとおりです。
my $year = (@ARGV) ? shift : 2001;
次に、次のように実行します。
perl test1.pl 2002
コマンドラインで年を指定しない場合、2001年はデフォルトになります。参照:perldoc -v @ARGV
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加