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

1.Using a text editor, create a text file containing five lines like this:

line one line two line three line four line five

These lines are indented in this document, but in your test file the only spaces in the file should be the single space between the words on each line. Your test program will be processing this file. Print the contents of the file in the report now for reference.

2. Printing the file. Create a simple perl program that will open the file, will assign the first line to a variable using something like $line = <TEST-INPUT>; , and then will print the contents of the variable.

Replies are listed 'Best First'.
Re: i am suppsed to do following. i am super new. can anyone help me?
by GrandFather (Saint) on Jan 27, 2016 at 20:27 UTC

    So what have you tried? What course materials are you using? What Perl documentation have you read?

    Perl is shipped with comprehensive documentation. At a command line try the following:

    • perldoc
    • perldoc perlintro
    • perldoc -f open
    • perldoc -f print
    Premature optimization is the root of all job security
Re: i am suppsed to do following. i am super new. can anyone help me?
by Anonymous Monk on Jan 27, 2016 at 20:22 UTC

    Are you having trouble with using a text editor to create the file (step 1), or with adding an open statement and a print statement to the code already provided in step two?

      In fairness he would have to remove a - too.

      adding the open and print statement

        perlintro#Files-and-I/O has documentation on how to open a file for input, and how to read from a file. Your assignment also shows the example, "$line = <TEST-INPUT>;", which will work to read a line from the file with one exception: Filehandles, like other identifiers in Perl shouldn't have a hyphen in them. Remove that hyphen and it becomes a valid identifier for a filehandle. Just make sure that your open opens the filehandle first.

        perlintro#Basic-syntax-overview shows how print can be used to print a string literal. perlintro#Perl-variable-types shows how to print a variable, such as $line.


        Dave