Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Perl command line switches

by AnomalousMonk (Bishop)
on Mar 27, 2020 at 04:42 UTC ( #11114704=note: print w/replies, xml ) Need Help??


in reply to Perl command line switches

... 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:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: Perl command line switches
by soonix (Canon) on Mar 27, 2020 at 08:19 UTC
    I don't now what a "scile" file is.
    Neither do I, but I assume it's an accidental contraction of "script file" :-)
      [scile] ... an accidental contraction of "script file" ...

      Very likely, although Google did cough up slice file :)


      Give a man a fish:  <%-{-{-{-<

Re^2: Perl command line switches
by Irakro1997 (Novice) on Mar 27, 2020 at 15:30 UTC
    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(); }

      It seems that you want to find out how your (unformatted) snippet parses the command line:

      ###################################################################### ###################################################################### 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.

        sorry i am not sure i understood your response ...so which argument should i pass to this script to generate the .xml file ?

        ###################################################################### 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_t_xml_hdr(); require "../vents.v$version.pl"; foreach my $box (@SBoxes) { printf(" <Unc>\n <ProcessArea name=\"%s\">\n", $box); &create_t_recs(\%P_UCventList, $gen_public, $box); printf(" </ProcessArea>\n </$area>\n"); } my $cvents = "c_vents.xml"; if (-f $cvents) { open(COXML, $cvents ) || die("Cannot Open $cvents"); printf while <COXML> ; } &print_t_xml_tail(); }
        would like to find out which arguments and how to parse when running the script

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11114704]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2020-06-01 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (12 votes). Check out past polls.

    Notices?