Section A.2.  Answers for Chapter 3

Table of Contents

A.2. Answers for Chapter 3

A.2.1. Exercise 1

The trick in this exercise is to let the modules do all of the hard work. It's a good thing we've shown you how to use modules! The Cwd module (cwd is an acronym for "current working directory") automatically imports the getcwd function. We don't have to worry about how it does its magic, but we can be confident that it does it correctly for most major platforms.

Once we have the current path in $cwd, we can use that as the first argument to the catfile method from the File::Spec function. The second argument comes from the input list to our map and shows up in $_.


use Cwd;
use File::Spec;

my $cwd = getcwd;

print map { "    " . File::Spec->catfile( $cwd, $_ ) . "\n" }
                glob( ".* *" );

A.2.2. Exercise 2

We can't give you much help installing the module, although if you run into problems, you might want to ask brian about them since he wrote the module, as well as the cpan program you can use to install it.

Once we have the module, we just have to follow the example in the documentation. Our program takes the ISB N from the command line and creates the new ISB N object, which we store in $isb n. Once we have the object, we simply follow the examples in the documentation.


use Business::ISB N;

my $isb n = Business::ISB N->new( $ARGV[0] );

print "ISB N is " . $isb n->as_string . "\n";
print "Country code:   " . $isb n->country_code . "\n";
print "Publisher code: " . $isb n->publisher_code . "\n";

Table of Contents
© 2000- NIV