[tpm] Subroutines and modules

arocker at Vex.Net arocker at Vex.Net
Wed Mar 6 14:01:21 PST 2013


Following our discussion last week, I've prepared a simple example of
refactoring repeated code, (naive), first to a subroutine, (subro), then
to a module (Counter.pm) used by a program (counts).

I'm courting public humiliation by publishing them. (See the attached.)
The first 2 are easy to run, but "counts" requires Counter.pm to be in one
of the directories named in @INC.

In every case, the result should be:
Number is 4
Number is 5

The programs are pretty useless in themselves, but I wanted to concentrate
on the essential points.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: naive
Type: application/octet-stream
Size: 329 bytes
Desc: not available
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20130306/3ed2c83e/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: subro
Type: application/octet-stream
Size: 634 bytes
Desc: not available
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20130306/3ed2c83e/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: counts
Type: application/octet-stream
Size: 264 bytes
Desc: not available
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20130306/3ed2c83e/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Counter.pm
Type: application/octet-stream
Size: 468 bytes
Desc: not available
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20130306/3ed2c83e/attachment-0003.obj>


More information about the toronto-pm mailing list