Another Example: Echo

Let's do another example. Here's a script that prompts you for some input, and then echoes that input to the screen, like this:

% echo.pl
Echo? Hi Laura
Hi Laura
%

Listing 1.2 shows the contents of the echo.pl script.

Listing 1.2. The echo.pl Script
1: #!/usr/local/bin/perl -w
2: # echo the input to the output
3:
4: print 'Echo? ';
5: $input = <STDIN>;
6: print $input;

You don't have to understand all of this script right now; I'll explain all the details tomorrow on Day 2. But you should feel comfortable typing and running this script, and have a general idea of how it works. Here's a quick run-through of the code:

Lines 1 and 2 are both comments: The first for the shebang line, the second to explain what the script ...

Get Sams Teach Yourself Perl in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.