Red Viper has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I am learning to use arrays with the lama book. One of the questions reads: "Write a program that reads a list of strings on separate lines until end-of-input and prints out the list in reverse order". The most recommended answer at the end of the book is the code below:

print "Enter some lines, the press Ctrl-D:\n"; print reverse <STDIN>;

I entered that code into strawberry perl,and that code didn't work. and when I tried to use Ctrl D the output was this "^D". Why isn't the answer code working and how do I write the proper code for the question?

Replies are listed 'Best First'.
Re: Arrays and the Llama Book
by davido (Cardinal) on Aug 07, 2014 at 04:13 UTC

    This is an OS-specific issue. On Windows you probably need to type [ctrl-Z][enter].


    Dave

      Red Viper: Anything and everything Strawberry is Windows.

      c:\@Work\Perl\monks>perl -wMstrict -le "print qq{Enter some lines, the press [Ctrl-Z][Enter]:}; print reverse <STDIN>; " Enter some lines, the press [Ctrl-Z][Enter]: line 1 line two 3rd line ^Z 3rd line line two line 1

Re: Arrays and the Llama Book
by Athanasius (Archbishop) on Aug 07, 2014 at 07:30 UTC

    Hello Red Viper,

    As davido says, Control-Z Enter works on Windows. I just have a comment on the node title’s reference to the Lama Book:

    The one-l lama,
    He’s a priest.
    The two-l llama,
    He’s a beast.
    And I will bet
    A silk pajama
    There isn’t any
    Three-l lllama.*

             — Ogden Nash

    *The author’s attention has been called to a type of conflagration known as a three-alarmer. Pooh.

    SCNR (ducks),

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re: Arrays and the Llama Book
by NetWallah (Canon) on Aug 07, 2014 at 04:14 UTC
    "code didn't work." is a very poor problem description - please review How do I post a question effectively?.

    When you run the code, after the prompt " "Enter some lines, the press Ctrl-D:" appears, enter a number or text, then hit the RETURN key. Enter another and hit RETURN. After a few of these, hit CTRL-D.

    The info you entered should then appear in reversed order.

            Profanity is the one language all programmers know best.

Re: Arrays and the Llama Book
by Red Viper (Novice) on Aug 09, 2014 at 04:17 UTC

    Thank you all. using Ctrl-Z worked.