On Nov 14, Douglas Houston said: >On Fri, 14 Nov 2003, Jeff 'japhy' Pinyan wrote: > >> On Nov 14, Douglas Houston said: >> >> >I am trying to initialize a dynamically-named array, i.e. with the >> >following test code (if I type "script.pl char" at the command prompt) I >> >get the message "array char contains 1 2 3" but I get a warning if 'use >> >strict' is on. Can anyone show me how it should be done (I would like to >> >use 'use strict'!)? >> >> You need to explain WHY you want to do this. There doesn't seem to me to >> be a good reason. Use a hash of array references. Don't turn off strict. > >WHY do I need to explain why I want to do this? There certainly isn't a >good reason to do it with the test code I posted. If there's NEVER a good >reason, what are the alternatives?
You need to explain why you want to do it is because it can create problems down the line. As for an alternative, I told you and showed you: use a hash of array references. $hash{foo} = [10, 20, 30]; print $hash{foo}[2]; # 30 >> And your "while (<$ARGV[0]>)" is weird, and not working why you think it >> works. > >a) explain how I think it works, and I don't know how you think it works, I'm just quite sure that you're using that construct because you think it is a standard thing to do, and it's not. How do YOU think it works? What if the first argument to your program was "foo*"? >b) explain why it really works. Perl thinks you're doing a file glob. <XXX> is a read from a filehandle unless XXX is something more complex than an identifier or a simple scalar. Thus, <$foo[$x]> is a file glob, glob($foo[$x]). If $foo[$x] has any wildcards or such, the shell expands that glob to all the files matching the pattern. But if it's just 'blah', glob('blah') returns 'blah'. Then, the next time, it returns undef, because it's done returning them. If that sounds complex, that's because it IS. Doing what you did works in some cases, for a bizarre reason. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]