CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced: Re: [tushar] if ($#ARGV != 0) what does it suggest: Edit Log



KevinR
Veteran


Jun 12, 2009, 11:23 AM


Views: 920
Re: [tushar] if ($#ARGV != 0) what does it suggest

When you pass arguments to a perl script from the command line they are stored in the @ARGV array. "$#name" is the numeric value of the last index of an array, $#ARGV is the value of the last index of the @ARGV array. Perl arrays start at index 0 (zero) so if the value of $#ARGV is not zero:


Code
if ($#ARGV != 0) {


it means the array has more than one element in it or none (its empty). Logically its better written like so:


Code
if (@ARGV != 1) {


Which means the length of the array is one, which is what you want. If its not one then evaluate the block and return the error.

Why you posted this in the Advanced forum though is odd. Post beginner questions in the Beginner forum please.
-------------------------------------------------


(This post was edited by KevinR on Jun 12, 2009, 11:24 AM)


Edit Log:
Post edited by KevinR (Veteran) on Jun 12, 2009, 11:24 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives