Perl - Goals for Beginners 3/26/2002

These tutorials and information are intended to assist a student with no prior knowledge of PERL, but some programming aptitude and experience, to learn how to use PERL for a range of simple tasks related to text files and text input from a user.  This page answers the question "How do I know when I've learned the basics that these pages intend to cover?"

You can test yourself by writing one or more programs to do all of the following things:

1. Open a text file and read and display each line in the file.

2. Open a text file to be read and a second file for output. Read the contents of the input file and store it in the output file. Check with the Notepad editor to verify that the second file now has the contents of the first one. (You might also try appending one or more lines of text to an existing text file, in contrast to replacing it.)

3. Prompt the user to use the keyboard enter a line of text on the screen and then display it back on the screen to show that you captured the input in a variable.

4. Prompt the user to enter text and then store that text in a file.

5. Prompt the user for several lines of input and store all of them in a text file.

6. Find a way to have the user enter several lines of text and then combine them into one line of text that you can display or save in a file. (I.e. figure out how to add and remove carriage returns)

7. GLOBBING! Find out what "globbing" is, and use it to open a group of files that meet some criteria, such as opening all the ".txt" files in a directory and then read and display the first line from each file, preceded by the name of the file it was in.

8. Regular Expressions:

      read in a group of lines from a text file, select lines that meet some criteria, and then replace a text pattern (e.g. Mary), with some other text pattern. Display the lines selected before and after the substitution.

9. SPLIT

     

What's Next:

If you can do all of the above you now have sufficient knowledge to a wide range of tasks with PERL. There is still a lot you could learn that would be useful. I suggest that the next areas to learn are (a) associative arrays and (b) more about Regular Expressions.  My experience is that these areas are somewhat hard to learn in and of themselves. They are best learned when you have a project for which they would be useful. So, if you get this far, see if you can think of a Perl project you might want to work on, or, see Harry Baya for some suggestions. I suggest thinking of projects that relate text records you might want to work with such as address lists, listings of CD collections, check book entries, family members including second cousins, and anything else that you might want to keep records about.