deep27ak has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I have a main function which almost works but it it lacks at someplaces.
My script's requirement is that it should run by default without any arguments but if the user wants to run the script with a custom file then he/she should use -c "filename with path"
It would be good if the script could also validate the xml file which is being passed as an argument under elsif condition
Main FunctionHere everything works untill I only runif (@ARGV > 0) { if ( $ARGV[0] eq "-c") { if ( ! -e "$ARGV[1]" ) { print "Provided xml file doesnot exists\n"; } elsif ( -f "$ARGV[1]") { $controlfile = $ARGV[1]; parse_xml(); update_exports(); } } else { usage (); } } elsif (@ARGV eq 0) { $controlfile = 'network.xml'; parse_xml(); update_exports(); exit 0; }
# perl script.pl -c Use of uninitialized value $ARGV[1] in string at nfs_security.pl line +171. Provided xml file doesnot exists
Here how can I print a warning message along with usage so that when $ARGV1 is not provided throw a warning
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: throw a warning if no argument were passed
by Corion (Patriarch) on Sep 21, 2015 at 11:24 UTC | |
|
Re: throw a warning if no argument were passed
by karlgoethebier (Abbot) on Sep 21, 2015 at 11:49 UTC | |
|
Re: throw a warning if no argument were passed
by Laurent_R (Canon) on Sep 21, 2015 at 16:24 UTC | |
|
Re: throw a warning if no argument were passed
by afoken (Chancellor) on Sep 21, 2015 at 19:23 UTC | |
by Laurent_R (Canon) on Sep 22, 2015 at 15:22 UTC | |
|
Re: throw a warning if no argument were passed
by Anonymous Monk on Sep 21, 2015 at 11:24 UTC |