On 6/8/11 Wed Jun 8, 2011 5:33 PM, "Sayth Renshaw" <flebber.c...@gmail.com> scribbled:
>> That looks fine, but Perl is trying to interpolate $mynames (which >> hasn't been initalised) into the string instead of indexing an element >> of @mynames. >> >> You may be running an old perl. Please check your version with >> >> perl -v > > I have 5.12.3 on this PC, The strawberry perl release. > >> >> and, in the mean time, fix your program by changing the print statement >> to >> >> print $mynames[$_-1], "\n"; >> >> HTH, >> >> Rob >> > Yes that got it all working. Regarding the actual $_ that as I read it > is the perl default. The $_ variable is the default variable for many Perl constructs, including the input operator, for and while loops, several built-in functions such as split, and the binding operator, etc. > > So in the context of this program is it saying whatever the default is > in the foreach loop for $mynames -1 from it(to correct the index) and > proceed. "$mynames[$_-1]" is a double-quoted string that contains an array element. The array element is indexed by the value of the scalar expression ($_-1). Your perl is apparently not properly detecting that the string contains an array element and attempting to evaluate the scalar variable $mynames instead of the array @mynames. $mynames[$_-1] in 'print $mynames[$_-1],"\n";' is an expression. The rules for evaluating expressions and for interpolating into double-quoted strings are different. The expression evaluation for $mynames[$_-1] is working correctly. Your Perl may have a bug, or something unknown is going on. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/