Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: Perl command line switches

by Corion (Patriarch)
on Mar 27, 2020 at 16:43 UTC ( [id://11114728]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^4: Perl command line switches
by Irakro1997 (Novice) on Mar 27, 2020 at 17:01 UTC

    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.

        Hi the output file should be an .XML file which i believe is in the code as "c_vents.xml" I am just ensure of which arguments to parse on the script to generate the .XML file i tried running the script as follow: perl create_s_t_xml.pl -v 0.1 and it ge , why does it not generate the .XML file ?

      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.

Re^4: Perl command line switches
by Irakro1997 (Novice) on Mar 27, 2020 at 17:04 UTC
    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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11114728]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 16:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found