develooper Front page | perl.beginners | Postings from June 2003

Re: Array Question

Thread Previous
From:
Rob Anderson
Date:
June 25, 2003 06:10
Subject:
Re: Array Question
Message ID:
20030625131058.7928.qmail@onion.perl.org
Hi Anthony

>"Anthony Beaman" <AnthonyBeaman@trginc.com> wrote in message
>news:B46773BE879E6D449E7AA93BEC10A4470159BFB9@exchange1.trghd.com...
>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>;
>

looks okay

>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";

looks okay too. You must be doing something that you've not posted here. Is
your print immediately after your stdin? Has your array gone out of scope.
The following is what you're trying to do, and works on my machince

#!/perl -w
use strict;
my @names;
@names = <STDIN>;
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! :-)


Post more of your prog if us still doesn't work

HTH

Rob



Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About