Front page | perl.beginners |
Postings from June 2003
RE: Array Question
From: Rich Fernandez
June 25, 2003 06:29
RE: Array Question
Message ID: 1E0DF3D8FB3DD54D8281CE6472C6A435038D63@mhexch01.arrow.com
LF (\n) is the default record separator, so if you type 3 names and press
all 3 names get placed in $array.
The next item(s) get placed in $array, etc depending on where you press
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.
From: Anthony Beaman [mailto:AnthonyBeaman@trginc.com]
Sent: Wednesday, June 25, 2003 9:18 AM
To: Paul Johnson
Subject: RE: Array Question
I typed in 3. For example, "Sam Mary Joe". I expect to get "I know Mary",
since she's  but I'm getting a blank space. I've tried this on NT and on
my 98 machine here at work.
From: Paul Johnson [mailto:firstname.lastname@example.org]
Sent: Wednesday, June 25, 2003 9:13 AM
To: Anthony Beaman
Subject: Re: Array Question
Anthony Beaman said:
> Hi! I'm still wallowing in Chapter 3 (Arrays. Why can't I
> 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.\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 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 - email@example.com
To unsubscribe, e-mail: firstname.lastname@example.org
For additional commands, e-mail: email@example.com