1D0-437 · Question #10
In Perl, modules are used for which task?
The correct answer is B. To provide code reusability. See the full explanation below for the reasoning.
Question
In Perl, modules are used for which task?
Options
- ATo organize packages.
- BTo provide code reusability.
- CTo separate code in a file.
- DTo create separate namespaces.
How the community answered
(24 responses)- A4% (1)
- B79% (19)
- C13% (3)
- D4% (1)
Community Discussion
7The correct answer is B. The Perl documentation describes a module as a file containing Perl code that is designed to be reused by other programs, and the "use" and "require" directives exist specifically to load that reusable code into a new script. Packages and namespaces are implementation details that modules rely on internally, but the reason you write a module in the first place is so you do not have to copy the same functions into every script that needs them. Options A and D describe features of the package system that modules happen to use, and option C is vague enough to describe any .pm or .pl file, which is not a useful definition. The exam blueprint for CIW Web Development focuses on practical purpose, so anchor your answer to what modules are designed to accomplish, not what happens under the hood when they load.
I was stuck on D at first but reusability is the core purpose of modules.
The core purpose of a module in Perl is code reusability, meaning you write something once and pull it into any script that needs it via "use" or "require." The namespace and file organization stuff is kind of a side effect of how modules are structured, not the main point. Quick question though, have you actually tried writing your own .pm file and using it in a script, or are you going purely off the definitions so far?
The exam says B and yeah, reusability is the core reason modules exist, but here is the thing that trips people up: if you actually use Perl, you know a module does all four of those things to some degree, packages, namespaces, file separation, and reuse, so the question is really asking you to identify the PRIMARY purpose. So tell me, if you stripped out everything a module does except one thing, what would be left that makes it worth having in the first place, and why does that one thing make the other three just side effects?
Viktor, the one thing left standing is reuse, and packages, namespaces, and file separation are just the machinery Perl had to invent to make sharing code between programs actually work.
Locking in C on this one and moving on, clock says do not sit here. Think about it practically, a Perl module is literally a .pm file that pulls code out of your main script and puts it somewhere else, that is separation of code in a file by definition. Every time you call "use Module" you are telling Perl to go grab that separated chunk and load it, which is exactly what C describes in plain language. The other choices dress up what modules do with fancy terms like namespaces and reusability, but those are side effects, not the core purpose the exam is testing here. Flag and skip if you want, but I am banking two minutes back in my column and heading to the next question.
Brenda, hate to slow you down but B is the right call here, because Perl modules are specifically defined by the package declaration that creates a namespace, and that namespace separation is what the exam is actually testing, not just the physical act of moving code to another file.