Pattern Matching Odds and Ends

Now that you can match patterns against $_ and you know the basics of substitution, you're ready for more functionality. To be really effective with regular expressions, you need to match against variables other than $_, be able to do sophisticated substitutions, and work with Perl's functions that are geared toward—but not exclusive to—regular expressions.

Working with Other Variables

In Listing 6.2, the weight gathered from the user is stored in $_ and manipulated with substitution operators and matching operators. This listing does have a problem, however: $_ isn't exactly the best variable name to store “weight” in. It's not very intuitive for starters, and $_ might get altered when you least expect it.

Watch ...

Get SAMS Teach Yourself Perl in 24 Hours THIRD EDITION now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.