getopts.plをGetopt :: Stdに置き換えます。

getopts.plをGetopt :: Stdに置き換えます。

私はCygwinバージョン2.10.0とPerl 5.26.0を使用しています。getopts.plに変更する必要がありますが、Getopt::Std行はどうなりますか&Getopts('F:f:');

#! /usr/bin/perl
require "getopts.pl" ;

# Perl script to take particle data and
# plot using (in this case) GMT to 
# produce a postscript file of specified size.
# Assumption is that this is a frame for a movie
# and hence that time information is meaningful

&Getopts('F:f:');
# Options:   -f: Filename for input data
# Options:   -F: Filename (root) for output data

# default values for parameters if not specified
if($opt_F eq "") {
  $opt_F = "ascii-conversion";
}

# Read the particle file ...   Assume 2D !! 
open(PAR,"< $opt_f") || die "File not found $opt_f\n";
open(OUT,"> $opt_F") || die "File not found $opt_F\n";
# open(OUT,">$name") || die "Cannot open file $name : $!\n";

ベストアンサー1

バラよりGetopt::Std:直接交換できる必要があります。

require "getopts.pl";
&Getopts('F:f:');

そして

use Getopt::Std;
getopts('F:f:');

use warnings;and(一般的に推奨)も使用する場合は、use strict;変数を事前に宣言する必要がありますour ($opt_F, $opt_f);。あるいは、ハッシュを使用することもできます。

getopts('F:f:', \my %opts);
$opts{f} # instead of $opt_f
$opts{F} # instead of $opt_F

おすすめ記事