From: Alec Ross Date: 2010-12-22T07:45:18+09:00 Subject: Re: Someone explain to me the logic behind ARGV[0] In message <4C1A26450D42B303@smtp205.alice.it>, Stefano Crocco writes >On Saturday 18 December 2010 19:12:57 Kaye Ng wrote: ... >> For example there's a code >> lines = File.readlines(ARGV[0]) >> Why do i need the [0]? >> >> I have another program, testingargv.rb with this code >> puts ARGV.join('-') >> (no [0] parameter) >> if i type in the command prompt, testingargv.rb test 123 >> the result is test-123 >> >> i don't understand the logic behind [0] in >> lines = File.readlines(ARGV[0]) >> >> thanks guys! > >ARGV is an array. Calling ARGV[0] returns the first argument of the array, ... This naming and usage stems back to the C programming language. There, argv is the conventional name for any command line arguments to the program, and it denotes an array of c-style strings. Elements of an array in C are accessed by a (0-based) index. Hence argv[0] gets the first argument value, argv[1] the second, and so on. HTH, Alec -- Alec Ross