4. Subroutines

A big part of Perl’s power as a dynamic language comes from its malleable subroutines. You don’t have to do much to define a subroutine. You don’t have to tell it how many parameters it will receive, or what types of data you will give it. You can pass a subroutine any list that you like and figure out what to do with it later. Although Perl is very permissive and gives you plenty of flexibility to decide things as late as possible. Despite that, there is a lot that you can do to keep yourself from being too flexible.

You don’t even have to define subroutines ahead of time, either. You can make new ones at run time and you can even redefine them later. You can write subroutines that create other subroutines. Each of those subroutines ...

Get Effective Perl Programming: Ways to Write Better, More Idiomatic Perl, Second Edition now with the O’Reilly learning platform.

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