On Fri, 4 May 2001, Ed Keer wrote:

> Here's a very beginner question.  I am working through
> the learning perl for win32 book and find that when I
> use <STDIN> to out info into an array, the program
> ignores the following print line.  For example, given
> the folliwng lines in the program:
>
> >@list = <STDIN>;
> >print "I will now print your list in reverse.\n";
> >print reverse(@list);
>
> the output skips over the first print line.
>
> I have a HP PC with Windows ME.  Any ideas on what
> could be goin on here?

I'm not sure what you mean that it is skipping over the first line.  I
pasted your code verbatim into a script and ran it, and it ran as
expected:

$ perl testout.pl
Hello
Hello again
I will now print your list in reverse.
Hello again
Hello

Try this one.  It's a little more complex, but provides a little more
control over the data entry, and strips off the trailing newline character
off of each element:

for (0..5) {

        $line = <STDIN>;
        chomp($line);
        print "you entered: $line\n";
        push(@list, $line);
}

print "I will now print your list in reverse.\n";
print join("\n", reverse(@list));

-- Brett
                                   http://www.chapelperilous.net/btfwk/
------------------------------------------------------------------------
Minors in Kansas City, Missouri, are not allowed to purchase cap pistols;
they may buy shotguns freely, however.

Reply via email to