O'Reilly logo

Sams Teach Yourself Perl in 21 Days, Second Edition by Rafe Colburn, Laura Lemay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Yet Another Example: Stock Price Converter

This final example uses split and patterns. The script in Listing 5.3 is a bit of an enhancement to the stock script on Day 3—the script where you typed in the beginning and ending prices of a stock, and it calculated the return on your investment. In that version of the script, you weren't allowed to enter stocks in the old-style format of fractional prices (14 5/8); we tested for that using regular expressions and printed an error.

This script isn't really a stock script; instead it's more of a price-checking and fixing script. It allows prices in plain numeric format. It checks for nondecimal characters and prints an error, as before. But if you enter in a price in a fractional format, it converts ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required