The plot thickens! I can get it to work if I have a data in the array, such as my script below:
print "Here are your friends: "; @friends = qw (Sam Joe Sally); print "@friends\n"; print "I know $friends[1]"; I still can't grab the element of an array that requests user input though. -----Original Message----- From: Derek Byrne [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 25, 2003 8:33 AM To: [EMAIL PROTECTED] Subject: RE: Array Question Hi Anthony, grabbed this from O'Reilly's Learning Perl : @rocks = qw/ bedrock slate lava /; foreach $rock (@rocks) { $rock = "\t$rock"; # put a tab in front of each element of @rocks $rock .= "\n"; # put a newline on the end of each } print "The rocks are:\n", @rocks; # Each one is indented, on its own line Still learning how to grab input from user via chomp, but this should help you work out how to print out all entries in an array using the foreach thingy :o) DerekB -----Original Message----- From: Anthony Beaman [mailto:[EMAIL PROTECTED] Sent: 25 June 2003 13:24 To: [EMAIL PROTECTED] Subject: Array Question Hi! I'm still wallowing in Chapter 3 (Arrays. Why can't I get it?!?!?!? ARGH!!!!!) of Learning Perl on Win32 Systems. I'm trying to create an exercise but I'm not getting the results that I want. Here's what I'm trying to do: I'm asking for a list of names: print "Name your friends: "; @names = <STDIN>; Then I want to pretend that I know the one of the friends. In this case, I'll choose the 2nd one and here's where I'm not getting what I want: print "I know $names[1].\n"; The output shows "I know ." Isn't "$names[whatever]" what I'm supposed to use to get an element of the array? I've tried this with numbers and have gotten the same results. What am I doing wrong? Thanks! :-) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] ************************************************************************ Meteor web site http://www.meteor.ie ************************************************************************ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]