Skip to Main Content
Sams Teach Yourself Perl in 21 Days, Second Edition
book

Sams Teach Yourself Perl in 21 Days, Second Edition

by Laura Lemay, Rafe Colburn
May 2002
Beginner content levelBeginner
704 pages
16h 37m
English
Sams
Content preview from Sams Teach Yourself Perl in 21 Days, Second Edition

Another Example: Stocks

To cement what you've learned today, let's work through another simple example that uses assignment, while loops, if conditionals, pattern matching, input, and both print and printf statements.

This example is a stock performance tracker. All you do is enter the purchase price of your stock and its current price, and it tells you if your investment has lost money, made money, or broken even, and by what percentage:

% stock.pl
Enter the purchase price: 45
Enter the current price: 48
Your investment has made money.
Your return on investment is 6.7%
% stock.pl
Enter the purchase price: 45
Enter the current price: 40
Your investment has lost money.
Your return on investment is -11.1%
% stock.pl Enter the purchase price:  ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Sams Teach Yourself Perl in 24 Hours

Sams Teach Yourself Perl in 24 Hours

Clinton Pierce
Perl Debugged

Perl Debugged

Peter Scott, Ed Wright

Publisher Resources

ISBN: 0672320355Purchase book