Tinkering with Perl

(Search & Sitemap) > Writing > Miscellaneous Nonfiction > Tinkering with Perl
Skip Back  Previous  28  29  30  31  32  33  34  35  36  37  Next  Skip Forward
Printer-Friendly Version

Input

The way I'm going to teach to do input, is as follows: Say that you want to input some line of text from the user, and store the result in the variable $UserResponse. The following two lines will accomplish that:

$UserResponse = <>;
chomp $UserResponse;

The first line reads a line into $UserResponse. But that includes the return character at the end of the line, which we generally don't need. The second line takes the extra character off.

In general, you should use something like these two lines when you want to input a line from the user.

See also:

Statements - Scalars - Input and Output - Output

Tinkering with Perl is a free book that provides an introduction to programming in Perl, as well as a basic reference for things like foreach in Perl, if-then, and if-then-else, in addition to providing a glossary where you can find definitions for concatenate and other terms.

Tinkering with Perl may be one of the most popular offerings on this site, but it's not the only attraction. You can read a tongue-in-cheek Game Review: Meatspace, read an even more offbeat customer service survey (whether or not you actually fill it out), and spend a few minutes wishing your boss would read, The Administrator Who Cried, "Important!" (Not to mention that there are other things you can read here besides tech stuff, from Janra Ball: The Headache to The Spectacles.)

Read more...

Top

(Search & Sitemap) > Writing > Miscellaneous Nonfiction > Tinkering with Perl
Skip Back  Previous  28  29  30  31  32  33  34  35  36  37  Next  Skip Forward
Printer-Friendly Version