Re: Perl command line switches
by AnomalousMonk (Archbishop) on Mar 27, 2020 at 04:42 UTC
|
... I inherited a scile file ...
I don't know what a "scile" file is.
... a command that you can use on the Perl script to get help on how to run that file or which arguments to pass to the script while running ...
There is no such general utility of which I am aware (update: but see perldoc as noted by haukex). However, any well-designed, non-trivial script will | should IMHO have a "usage" or "help" message of some kind that might look something like
use constant USAGE => <<"EOT";
usage:
perl $0 -yz input_file_name output_file_name
where:
-y optional: command line switch to enable Y
-z optional: command line switch to enable Z
input_file_name required: input file name
output_file_name required: output file name
etc...
EOT
...
die USAGE unless @ARGV >= 2;
...
(where $0 is (more or less) the script name; see perlvar). If you can't find such code, then after examining the script to try to determine that it will do nothing irreversible, maybe try invoking the script with no command line arguments; this may trigger a usage/help message. There may also be a command line flag or switch like -h --help -? /h /? or similar supported by the script. Maybe also look for the presence of modules Getopt::Std or Getopt::Long used to manage command line options and arguments and see what they're doing in the script.
Give a man a fish: <%-{-{-{-<
| [reply] [d/l] [select] |
|
I don't now what a "scile" file is.
Neither do I, but I assume it's an accidental contraction of "script file" :-)
| [reply] |
|
| [reply] [d/l] |
|
Hi All
thanks for trying to respond there is a typo instead of "scile file" i meant to say "script file" perl I have a piece of the code below I would like to know when running this code if the script name is convert.pl i tried to run like this below:
example : perl convert.pl .?.?.? . how do i display the arguments list that are supposed to be passed to this script when running it to generate the correct output ?
######################################################################
######################################################################
sub main
{
my $gen_public = 0;
my $version = "0.1";
while ($arg = shift @ARGV)
{
$gen_public = 1 if ($arg eq "-p");
if ($arg eq "-v")
{
$version = shift @ARGV;
$XLFILE =~ s/v0\.1/v$version/g;
}
}
&print_tagec_xml_hdr();
require "../spr_uc_events.v$version.pl";
foreach my $box (@SPRBoxes)
{
printf(" <Uncore>\n <ProcessorArea name=\"%s\">\n", $box);
&create_tagec_recs(\%SPR_UCEventList, $gen_public, $box);
printf(" </ProcessorArea>\n </$area>\n");
}
my $coreevents = "core_events.xml";
if (-f $coreevents)
{
open(COREXML, $coreevents ) || die("Cannot Open $coreevents");
printf while <COREXML> ;
}
&print_tagec_xml_tail();
}
| [reply] [d/l] [select] |
|
######################################################################
######################################################################
sub main
{
my $gen_public = 0;
my $version = "0.1";
while ($arg = shift @ARGV)
{
$gen_public = 1 if ($arg eq "-p");
if ($arg eq "-v")
{
$version = shift @ARGV;
$XLFILE =~ s/v0\.1/v$version/g;
}
}
# .... rest elided
}
You run Perl scripts for example by using perl -w path/to/that/script.pl. Looking at the code, it looks for a -p switch or a -vswitch and sets some variables.
All the values from the command line get stuffed into the @ARGV array, see perlvar on that.
| [reply] [d/l] [select] |
|
|
|
|
|
|
Re: Perl command line switches
by haukex (Archbishop) on Mar 27, 2020 at 06:35 UTC
|
In addition to AnomalousMonk's excellent post, note that some Perl scripts have embedded documentation (POD). You can access it via perldoc scriptname.pl, or simply by looking at the source code of the script.
| [reply] [d/l] |
Re: Perl command line switches
by davido (Cardinal) on Mar 27, 2020 at 19:56 UTC
|
One of the things you may want to do as you take over ownership of this script could be to convert it to use Getopt::Long and Pod::Usage, and to write the POD so that it is compatible with pod2usage. You've got some work to do on understanding the script. But you can leave it in a better state when you're done with it.
| [reply] [d/l] |
Re: Perl command line switches
by camtauxe (Sexton) on Mar 27, 2020 at 15:13 UTC
|
Perl has a syntax for embedded documentation called POD (perlpod). It's possible that that's what you're thinking of. If the author of the original file was kind enough to include any of this documentation in the file, then you can read it on the command-line with the pod2text command. Just enter:
pod2text <myscript.pl>
And that will print out any POD that exists in the file.
| [reply] [d/l] |