in reply to Re: Perl command line switches
in thread Perl command line switches

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(); }

Replies are listed 'Best First'.
Re^3: Perl command line switches
by Corion (Patriarch) on Mar 27, 2020 at 16:43 UTC

    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(); }

        Do you know what the -p switch does in your script?

        Do you know what the -v switch does in your script?

        The -v switch consumes one more argument from @ARGV and writes into a variable $version. That value is then stripped out from the string contained in the $XLFILE variable.

        You don't show us where in your code the $XLFILE variable is populated, but most likely that file is what you want?

        Or maybe the output filename is c_vewnts.xml - that is mentioned somewhere later.

        My approach would be to talk to the people who wrote that program, or to the people who use that program and ask them about what the program does, and what its input parameters are and where it writes its output.

        In addition to what Corion said, are you sure your main() is called? And more, does it get past that require "../vents.v$version.pl";? If the main() sub is called then you should be able to see some XML header if all goes well... Best thing to do is to make a copy of that script and at some places add print "here1\n"; etc. to see what is the flow.

      would like to find out which arguments and how to parse when running the script