Front page | perl.beginners |
Postings from June 2003
RE: Array Question
Thread Previous
|
Thread Next
From:
Rich Fernandez
Date:
June 25, 2003 06:29
Subject:
RE: Array Question
Message ID:
1E0DF3D8FB3DD54D8281CE6472C6A435038D63@mhexch01.arrow.com
Hi Anthony,
LF (\n) is the default record separator, so if you type 3 names and press
enter,
all 3 names get placed in $array[0].
The next item(s) get placed in $array[1], etc depending on where you press
enter.
If your input looks like this:
Fred Barney <enter>
Wilma Betty <enter>
your program will print "Wilma Betty" because each <enter> will add a LF.
HTH
richf
-----Original Message-----
From: Anthony Beaman [mailto:AnthonyBeaman@trginc.com]
Sent: Wednesday, June 25, 2003 9:18 AM
To: Paul Johnson
Cc: beginners@perl.org
Subject: RE: Array Question
I typed in 3. For example, "Sam Mary Joe". I expect to get "I know Mary",
since she's [1] but I'm getting a blank space. I've tried this on NT and on
my 98 machine here at work.
-----Original Message-----
From: Paul Johnson [mailto:paul@pjcj.net]
Sent: Wednesday, June 25, 2003 9:13 AM
To: Anthony Beaman
Cc: beginners@perl.org
Subject: Re: Array Question
Anthony Beaman said:
> 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! :-)
How many names did you type in? $names[1] is the second
element of the
array because arrays start at zero by default, so you will
need to type in
at least two names.
--
Paul Johnson - paul@pjcj.net
http://www.pjcj.net
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
Thread Previous
|
Thread Next