I also agree that the modules mentioned are great things ... for times when
modules are needed.
Otherwise, I am a fan of:
if (@ARGV) do {blah;}
Of course, "defined" is good too, for the pedantic.
Sometimes modules are great, sometimes they are overkill ;)
-~.-~.-~.-~.-~.-~.-~.-~.-~.-~
-~
-~ Cliff Frensley
-~ [EMAIL PROTECTED]
-~ Seattle, WA
-~
-~
-.
On Mon, 27 Jan 2003, Geaslin, Andrew - GPB wrote:
> I agree that GetOpt::Std or GetOpt::Long are excellent (I use them often).
> But if you want to roll your own you can treat @ARGV like any other array.
>
> if (@ARGV)
> { print "parameters present\n";
> }
> else
> { print "no parameters\n";
> }
>
>
>
> -Andrew
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> There are other caveats to be aware of as well when it comes to writing your
> own switches. I would recommend looking into the GetOpt::Std module that
> comes standard with Perl. It can do what you want and comes out much
> cleaner.
>
>
>
> Is there a better way to detect a parameter given in a command line? For
> example, to run the script (obviously) c:\>script.pl I have also added
> some "switches" to help with setup of the options (like) c:\>script.pl /h
> to see a help message
> c:\>script.pl /i to generate a new options file, etc. And it is all
> working well.
>
> Question: When NOT using a switch (just running the script), I am getting
> a message I would like to supress or preferable fix by using more correct
> code...
> Use of uninitialized value in string ne at logsaver.pl line 33.
>
> This is of course because I have not included a /h or /i value. The script
> runs, but I would prefer it ran cleanly with no message.
>
> Code is this....
> # if no parameters passed, skip. If something passed, then do.
> if($ARGV[0] ne ""){ do this stuff; }
>
> Thank you!
>
>
> Glenn Meyer
>
>
> _______________________________________________
> Perl-Win32-Admin mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> _______________________________________________
> Perl-Win32-Admin mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> _______________________________________________
> Perl-Win32-Admin mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs