Perl Cookbook 2nd Edition Tom Christiansen Download PDF
Perl Cookbook 2nd Edition Tom Christiansen Download PDF
https://ebookultra.com/download/perl-cookbook-2nd-edition-tom-
christiansen/
https://ebookultra.com/download/postgis-cookbook-2nd-edition-edition-
corti/
https://ebookultra.com/download/arduino-cookbook-2nd-edition-edition-
margolis/
https://ebookultra.com/download/ruby-cookbook-2nd-edition-lucas-
carlson/
https://ebookultra.com/download/primefaces-cookbook-2nd-edition-mert-
caliskan/
ElasticSearch Cookbook 2nd Edition Alberto Paro
https://ebookultra.com/download/elasticsearch-cookbook-2nd-edition-
alberto-paro/
https://ebookultra.com/download/language-universals-1st-edition-
morten-h-christiansen/
https://ebookultra.com/download/digital-photography-an-
introduction-2nd-edition-tom-ang/
https://ebookultra.com/download/ethics-the-key-thinkers-2nd-edition-
tom-angier/
https://ebookultra.com/download/beginning-perl-3rd-edition-james-lee/
Perl Cookbook 2nd Edition Tom Christiansen Digital
Instant Download
Author(s): Tom Christiansen; Nathan Torkington
ISBN(s): 9780596003135, 0596003137
Edition: 2
File Details: PDF, 3.23 MB
Year: 2003
Language: english
Perl Cookbook ™
Other Perl resources from O’Reilly
Related titles Programming Perl Perl 6 Essentials
Learning Perl Learning Perl Objects,
CGI Programming with Perl References & Modules
Computer Science & Perl Mastering Regular
Programming Expressions
Web, Graphics & Perl/Tk Practical mod_perl
Games, Diversions & Perl Perl Pocket Reference
Culture Perl in a Nutshell
Programming Web Services Perl Graphics Programming
with Perl
Perl.com is the central web site for the Perl community. It is the
perfect starting place for finding out everything there is to know
about Perl.
Perl Cookbook
™
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly Media, Inc. books may be purchased for educational, business, or sales promotional use.
Online editions are also available for most titles (safari.oreilly.com). For more information, con-
tact our corporate/institutional sales department: (800) 998-9938 or [email protected].
Printing History:
August 1998: First Edition.
August 2003: Second Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered
trademarks of O’Reilly Media, Inc. The Cookbook series designations, Perl Cookbook, the image
of a bighorn sheep, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the
designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of
a trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors
assume no responsibility for errors or omissions, or for damages resulting from the use of the
information contained herein.
ISBN: 0-596-00313-7
ISBN13: 978-0-596-00313-5
[M] [12/06]
Table of Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
1. Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Accessing Substrings 7
1.2 Establishing a Default Value 10
1.3 Exchanging Values Without Using Temporary Variables 12
1.4 Converting Between Characters and Values 13
1.5 Using Named Unicode Characters 15
1.6 Processing a String One Character at a Time 17
1.7 Reversing a String by Word or Character 19
1.8 Treating Unicode Combined Characters as Single Characters 21
1.9 Canonicalizing Strings with Unicode Combined Characters 22
1.10 Treating a Unicode String as Octets 24
1.11 Expanding and Compressing Tabs 25
1.12 Expanding Variables in User Input 27
1.13 Controlling Case 29
1.14 Properly Capitalizing a Title or Headline 31
1.15 Interpolating Functions and Expressions Within Strings 33
1.16 Indenting Here Documents 35
1.17 Reformatting Paragraphs 39
1.18 Escaping Characters 41
1.19 Trimming Blanks from the Ends of a String 43
1.20 Parsing Comma-Separated Data 44
1.21 Constant Variables 48
1.22 Soundex Matching 50
v
1.23 Program: fixstyle 52
1.24 Program: psgrep 55
2. Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
2.1 Checking Whether a String Is a Valid Number 60
2.2 Rounding Floating-Point Numbers 63
2.3 Comparing Floating-Point Numbers 67
2.4 Operating on a Series of Integers 68
2.5 Working with Roman Numerals 70
2.6 Generating Random Numbers 71
2.7 Generating Repeatable Random Number Sequences 72
2.8 Making Numbers Even More Random 73
2.9 Generating Biased Random Numbers 74
2.10 Doing Trigonometry in Degrees, Not Radians 76
2.11 Calculating More Trigonometric Functions 77
2.12 Taking Logarithms 78
2.13 Multiplying Matrices 80
2.14 Using Complex Numbers 82
2.15 Converting Binary, Octal, and Hexadecimal Numbers 83
2.16 Putting Commas in Numbers 84
2.17 Printing Correct Plurals 85
2.18 Program: Calculating Prime Factors 87
4. Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
4.1 Specifying a List in Your Program 111
4.2 Printing a List with Commas 113
vi | Table of Contents
4.3 Changing Array Size 115
4.4 Implementing a Sparse Array 117
4.5 Iterating Over an Array 119
4.6 Iterating Over an Array by Reference 122
4.7 Extracting Unique Elements from a List 124
4.8 Finding Elements in One Array but Not Another 126
4.9 Computing Union, Intersection, or Difference of Unique Lists 128
4.10 Appending One Array to Another 130
4.11 Reversing an Array 131
4.12 Processing Multiple Elements of an Array 132
4.13 Finding the First List Element That Passes a Test 134
4.14 Finding All Elements in an Array Matching Certain Criteria 136
4.15 Sorting an Array Numerically 138
4.16 Sorting a List by Computable Field 139
4.17 Implementing a Circular List 143
4.18 Randomizing an Array 144
4.19 Program: words 144
4.20 Program: permute 146
5. Hashes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
5.1 Adding an Element to a Hash 152
5.2 Testing for the Presence of a Key in a Hash 153
5.3 Creating a Hash with Immutable Keys or Values 155
5.4 Deleting from a Hash 156
5.5 Traversing a Hash 157
5.6 Printing a Hash 160
5.7 Retrieving from a Hash in Insertion Order 161
5.8 Hashes with Multiple Values per Key 162
5.9 Inverting a Hash 164
5.10 Sorting a Hash 166
5.11 Merging Hashes 167
5.12 Finding Common or Different Keys in Two Hashes 169
5.13 Hashing References 170
5.14 Presizing a Hash 171
5.15 Finding the Most Common Anything 172
5.16 Representing Relationships Between Data 173
5.17 Program: dutree 174
Table of Contents | ix
8.26 Program: laston 342
8.27 Program: Flat File Indexes 343
9. Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
9.1 Getting and Setting Timestamps 351
9.2 Deleting a File 353
9.3 Copying or Moving a File 354
9.4 Recognizing Two Names for the Same File 355
9.5 Processing All Files in a Directory 356
9.6 Globbing, or Getting a List of Filenames Matching a Pattern 358
9.7 Processing All Files in a Directory Recursively 359
9.8 Removing a Directory and Its Contents 362
9.9 Renaming Files 363
9.10 Splitting a Filename into Its Component Parts 365
9.11 Working with Symbolic File Permissions Instead of Octal Values 367
9.12 Program: symirror 369
9.13 Program: lst 370
x | Table of Contents
11. References and Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
11.1 Taking References to Arrays 413
11.2 Making Hashes of Arrays 415
11.3 Taking References to Hashes 416
11.4 Taking References to Functions 417
11.5 Taking References to Scalars 420
11.6 Creating Arrays of Scalar References 421
11.7 Using Closures Instead of Objects 423
11.8 Creating References to Methods 424
11.9 Constructing Records 425
11.10 Reading and Writing Hash Records to Text Files 428
11.11 Printing Data Structures 429
11.12 Copying Data Structures 431
11.13 Storing Data Structures to Disk 432
11.14 Transparently Persistent Data Structures 434
11.15 Coping with Circular Data Structures Using Weak References 435
11.16 Program: Outlines 438
11.17 Program: Binary Trees 441
Table of Contents | xi
12.19 Writing Extensions in C with Inline::C 486
12.20 Documenting Your Module with Pod 487
12.21 Building and Installing a CPAN Module 489
12.22 Example: Module Template 492
12.23 Program: Finding Versions and Descriptions of Installed Modules 493
Table of Contents | xv
20.6 Extracting or Removing HTML Tags 802
20.7 Finding Stale Links 804
20.8 Finding Fresh Links 805
20.9 Using Templates to Generate HTML 807
20.10 Mirroring Web Pages 810
20.11 Creating a Robot 811
20.12 Parsing a Web Server Log File 812
20.13 Processing Server Logs 813
20.14 Using Cookies 816
20.15 Fetching Password-Protected Pages 817
20.16 Fetching https:// Web Pages 818
20.17 Resuming an HTTP GET 819
20.18 Parsing HTML 820
20.19 Extracting Table Data 823
20.20 Program: htmlsub 825
20.21 Program: hrefsub 827
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897
But I'm bound to say that they very often arrange it shall not be a
white man's and emphatically not a white woman's country. It suits
somebody's plan that the country should have an evil reputation.
Goldfields, too, must never be judged in the same category as one
judges the ordinary settlements in a country. When I was a tiny child
I learned to discriminate, and to know that “diggers” must not be
judged by the rules that guide the conduct of ordinary men. The
population of a goldfield are a wild and reckless lot, and they lead
wild and utterly reckless lives, and die in places where other people
manage to live happily enough.
When the gold first “broke out” in Victoria, my father was Gold
Commissioner on the Buckland River, among the mountains in the
north-eastern district, and I have heard him tell how the men used
to die like flies of “colonial” fever, and the theory was that there was
some emanation from the dense vegetation that was all around
them. Nowadays the Buckland is one of the healthiest spots in a
very healthy country, and no one ever gets fever of any sort there.
Now I do not wish to say that West Africa is one of the healthiest
countries in the world, but I do say that men very very often work
their own undoing.
“You should see Tarkwa,” said a man to me, who was much of my
way of thinking, “when an alcoholic wave has passed over it!”
Eduaprim was another mine I went to see from Tarkwa. But it was
in direct contrast to Prestea, though it too was in the heart of the
forest country. No railway led to it; I had to go by hammock, and so
I got my first taste of forest travelling, and enjoyed it immensely.
It is a solitary mine about nine miles from Tarkwa, and I started
off early in the morning, and noticed as I went that the industry is,
for good or ill, clearing the forests of West Africa, opening up the
dark places, even as it did in my country over fifty years ago. Along
the hillsides we went to Eduaprim, past mines and clearings for
mining villages; sometimes the road was cut, a narrow track on the
side of the hill, with the land rising up on one side and falling sheer
on the other, sometimes a little river had to be bridged, and the road
went on tunnel-like through the forest that must disappear before
the furnaces, but at last I arrived at the top of the hill, and on it,
commanding a wonderful view over the surrounding country, stood a
bungalow, in a garden that looked over the tops of range upon
range of high hills. I saw a storm come sweeping across the country,
break and divide at the hilltop upon which I stood, and pass on,
veiling the green hills in mist, which rolled away from the hills
behind, leaving them smiling and washed and clean under a blue
sky. If for no other sight than that, that journey into the hills was
worth making.
The wife of the manager of the mine was a fellow-countrywoman
of mine. She liked West Africa, kept her health there, and felt
towards it very much as I did. No one likes great heat. The
unchanging temperature is rather difficult to bear for one
unaccustomed to it, but she thought it might be managed by a
woman interested in her work and her husband, and as for the other
discomforts—like me, she smiled at them. “The people who grumble
should live in Australia,” said she, “and do their own work, cooking,
washing, scrubbing. Do it for a week with the temperature averaging
100 degrees in the shade, and they wouldn't grumble at West Africa,
and wouldn't dream of being sick.” And yet this contented woman
must have led a very lonely life. Some wandering man connected
with the mines, or a stray Commissioner, would come to see her
occasionally, and the news of the world would come on men's heads
from Tarkwa. And, of course, I suppose there was always the mine,
which was her husband's livelihood. They took me into the bush
behind the bungalow and showed me a great mahogany tree they
had cut down, and then they showed me what I had seen many and
many a time in my life before, but never in Africa—men washing the
sand for gold. They were “dollying” it first, that is crushing the hard
stone in iron vessels and then washing it, and the “show,” I could
see for myself, was very good.
I lingered in Eduaprim; the charm of talking with a woman who
found joy in making a home in the wilderness was not to be lightly
foregone, and I only went when I remembered that it was the rainy
season, the roads were bad, and Tarkwa was away over those
forbidding hills.
And from Tarkwa I went up the line to Obuasi.
This railway line that runs from Sekondi to Kumasi, the capital of
Ashanti, is a wonderful specimen of its class. Every day sees some
improvement made, but, being a reasonable being, I cannot help
wondering what sort of engineers laid it out. It presents no
engineering difficulties, but it was extremely costly, and meanders
round and round like a corkscrew. They are engaged now in
straightening it, but still they say that when the guard wants a light
for his pipe all he has to do is to lean out of his van and get it from
the engine. It was laid through dense forest, but the forest is going
rapidly, the trees being used up for fuel. In the early days, too, these
trees were a menace, for again and again, when a fierce tornado
swept across the land, the line would be blocked by fallen trees, a
casualty that grows less and less frequent as the forest recedes.
When first the line was opened they tell me all passengers were
notified that they must bring food and bedding, as the company
could not guarantee their being taken to their destination. There is
also the story of the distracted but pious negro station-master, who
telegraphed to headquarters, “Train lost, but by God's help hope to
find it.” It is a single line of 168 miles, so I conclude his trust in the
Deity was not misplaced.
Obuasi, on the borders of Ashanti, is the great mine of West
Africa, a mine that pays, I think, something like 75 per cent, on its
original shares, and even at their present value pays 12 per cent. It
is enough to set everyone looking for gold in West Africa.
And like Prestea, Obuasi is the mine, and the mine only. There
are, I think, between eighty and one hundred white men, all, save
the few Government officials and storekeepers, in some way or
another connected with the mine, and the place at night looks like a
jewel set in the midst of the hills, for it is lighted by electricity. Every
comfort of civilisation seems to be here, save and except the white
woman, who is conspicuous by her absence. “We want no white
women,” seems to be the general opinion; an opinion, I deeply
regret to say, warranted by my experience of the average English
woman who goes to West Africa.
The place is all hill and valley, European bungalows built on the
hills, embowered generally in charming gardens such as one sees
seldom in the Colony, and the native villages—for there are about
five thousand black men on the books of the mine—in the valleys.
There are miles of little tramway railways too, handling about 35,000
tons a month, more, they tell me, than the Government railway
does, and the mine pays Government a royalty of £25,000 a year.
Obuasi is a fascinating, beautiful place; I should have liked to have
spent a month there, but it is not savagery. It is as civilised in many
ways as London itself. I stayed in the mining manager's bungalow,
and am very grateful to him for his hospitality, and the manager's
bungalow is a most palatial place, set on the top of a high hill in the
midst of a beautiful garden. Palm and mango and grape-fruit trees,
flamboyant, palms, dahlias, corallita, crotons, and roses, the most
beautiful roses in the world, red, white, yellow, pink, everywhere; a
perfect glory of roses is his garden, and the view from the verandah
is delightful. His wide and spacious rooms are panelled with the
most beautiful native woods, and looking at it with the eyes of a
passer-by, I could see nothing but interest in the life of the man who
had put in a year there. He will object strongly, I know, to my writing
in praise of anything West-African, and say what can I know about it
in a brief tour. True enough, what can I know? But at least I have
seen many lands, and I am capable of making comparisons.
Every man I met here pointed out to me the evils of life in Africa.
“You make the very worst of it,” said I, and proceeded to tell the
story of a bridge party in a Coast town that began at three o'clock
on Friday afternoon and ended up at ten o'clock on Monday
morning.
“And if those men have fever,” said I, feeling I had clinched my
argument, “they will set it down to the beastly climate.”
“So it is,” said my opponent emphatically; “we could always do
that sort of thing in Buluwayo.”
I thereby got the deepest respect for the climate of Buluwayo, and
a most doubtful estimate of the character of the pioneer Englishman.
Perhaps I look on these things with a woman's narrow outlook, but
I'm not a bit sorry for the men who cannot dissipate without paying
for it in Africa. I heartily wish them plenty of fever.
The manager took me on a trolley along one of these little lines,
right away into the hills. This was a new form of progression. A seat
for two people was fixed on a platform and pushed along the line,
uphill or on the flat, by three or four negroes, and fairly flew by its
own weight downhill. It was a delightful mode of progression, and as
we flew along, Xi my host, while pointing out the sights,
endeavoured to convert me, not to the faith that West Africa was
unfit for the white woman, that would have been impossible, but
that the mining industry was a very great one and most useful to the
Colony. And here he succeeded.
A
nd when I had been to Obuasi nothing remained but to go up
the line and see Kumasi and go as far beyond as the time at
my disposal would allow.
I wonder if English-speaking people have forgotten yet the siege
of Kumasi. For me, I shall never forget, and it stands out specially in
my mind because I know some of the actors, and now I have seen
the fort where the little tragedy took place; for, put it what way you
will, it was a tragedy, for though the principals escaped, some with
well-merited honour, the minor actors died, died like flies, and no
man knoweth even their names.
It was dark when I reached Kumasi and got out on to the platform
and was met by the kind cantonment magistrate, put into a
hammock, and carried up to the fort, and was there received by the
Chief Commissioner and his pretty bride, one of the two white
women who make Kumasi their home, I had seen many forts, old
forts along the Coast, but this fort was put up in 1896, and in 1900
its inmates were fighting for their lives. In it were shut up the
Governor, his wife, two or three unfortunate Basel missionary
women, a handful of troops, and all the other white people in the
place. Standing on the verandah overlooking the town to-day, with a
piano playing soft music and a dining-table within reach set out with
damask and cut-glass and flowers and silver, it is hard to believe that
those times are only ten years back. I have heard men talk of those
days, and they are reticent; there are always things it seems they
think they had better not tell, and I gather that the then Governor
was not very much beloved, and that no one put much faith in him.
The rebellion started somewhere to the north, and by the time it
reached Kumasi it was too late to fly, for it was a good eight days'
hard march to the Coast through dense forest. The nearest possible
safety outside that fort lay beyond the River Prah, at least three or
four days' march away. Every white man and many of the black who
were not Ashantis had taken refuge in the fort, which was crowded
to suffocation, and outside, in front of the fort, camped the
friendlies, safe to a certain extent under the white man's guns, but
dying slowly because the white man could not give what he had not
got himself—food; and here they died, died of disease and hunger
and wounds, and the reek of their dying poisoned the air so that the
white man, starving behind his high walls of cement, was like to
have his end accelerated by those who stood by him.
And out beyond, where the English town now stands, with broad
streets planted with palms and mangoes and ficus, were the
encampments of fierce Ashanti warriors, their cloths wound round
their middles, their hair brushed fiercely back from their foreheads,
their powder-flasks and bullet-bags slung across their shoulders, and
their long Danes in their hands, the locks carefully covered with a
shield of pigskin. The same man, very often the very same
individual, walks about the streets of Kumasi to-day, and if he wears
a tourist cap and a shirt, torn, ragged, and dirty, he is at least a
peaceful citizen, and ten years hence he will probably, like the
Creoles in Sierra Leone, be talking of “going home.” But it was
ghastly in the fort then. It was small and it was crowded to
suffocation. The nearest help was at Cape Coast, nigh on 200 miles
away, and between lay the dense forest that no man lightly dared.
The Ashanti too was the warrior of the Coast, and the difficulty was
even to get carriers who would help to move a force against him.
Shut up in the fort there they looked out and waited for help and
waited for death that ever seemed coming closer and closer.
Kumasi is set in a hollow, and round it, pressing in on every side,
was the great forest. Away to the south went the road to Cape
Coast, but it was but a track kept open with the greatest difficulty,
and hidden in the depths of the forest on either hand were these
same warriors. Truly the chances of the people in the fort seemed
small, small indeed. And day after day passed and there was no sign
of help. Provisions were getting low, ammunition was running short,
and from the Ashanti no mercy could be expected. It was war to the
death. Any man or woman who fell into their hands could expect
nothing but torture. I gather that his advisers would have had the
Governor start for the Coast at once on the outbreak of hostilities,
but he could not make up his mind, and lingered and lingered,
hoping for the help that did not, that could not come. No one has
ever had a word of praise for that Governor, though very gallantly
the men under him came out of it. Starvation and death stared them
all in the face; the gallant little garrison, heavily handicapped as it
was, could certainly hold out but little longer, and the penalty of
conquest was death—death, ghastly and horrible.
At last the Governor gave in and they started, a forlorn little
company, for the River Prah, which had generally set a bound to
Ashanti raids. The Governor's wife was carried in a hammock, but
the Basel missionary women, who had escaped with only the clothes
they stood up in, walked, for the hammock-boys were too weak to
carry them, and they had to tramp through mud and swamp. The
soldiers did their best to protect the forlorn company, the friendlies
crowded after, a tumultuous, disorderly crew fleeing before their
enemies, and those same enemies hung on their flanks, scrambled
through the forest, ruthlessly cut off any stragglers, and poured
volleys from their long Danes into the retreating company. Knowing
the forest, I wonder that one man ever escaped alive to tell the tale;
that the principal actors did, only shows that the Ashanti was not the
practised warrior the Coast had always counted him. Had those
Ashantis been the lean Pathan from the hills of northern India, not a
solitary man would have lived to tell the tale, and the retreat from
Kumasi would have taken its place with some of those pitiful stories
of the Afghan Border. But one thing the Ashanti is not, he is not a
good marksman. He blazes away with his long Dane, content to
make a terrific row without making quite sure that every bullet has
reached its billet. And so, thanks to the bad marksmanship of the
Ashantis, that little company got through.
But let no man think I am in any way disparaging the men who
fought here, who by their gallantry brought the Governor and his
wife through. Major Armitage and his comrades were brave men of
whom England may well be proud, men worthy to take their places
beside Blake and Hawkins and all the gallant Britons whose names
are inscribed on the roll of fame; they fought against desperate
odds, they were cruelly hampered by the helpless people under their
care, and they stuck beside them, though by so doing they risked
not only death, but death by ghastly torture. Some of them died,
some of them got through—they are with us still, young men, men
in the prime of life—and when we tell our children tales of the way
England won her colonies, we may well tell how that little company
left the fort of Kumasi, every man who was wise with cyanide of
potassium in his pocket, and fought his way down to the Prah.
But even though they went south they were not going to abandon
Kumasi, which had been won at the cost of so much blood, and in
that fort were left behind three white men and a company of native
soldiers. All in good time the relief must come, and till then they
must hold it.
A verandah hangs round the fort nowadays that the piping times
of peace have come, but still upstairs in the rooms above are the
platforms for the gun-carriages, and I climbed up on them and
walked along the verandahs and wondered how those men must
have felt who had looked out from the self-same place ten years
ago. If no help came, if waiting were unduly prolonged, they would
die, die like rats in a hole, and the men in their companies were
dying daily. They were faithful, those dark soldiers of the Empire, but
they were dying, dying of disease and hunger, and their officers
could not help them, for were they not slowly dying themselves?
Rumours there were of the relief force, but they were only rumours,
and the spectres of disease and starvation grew daily. Could they
hold out? Could they hold out? The tale has been told again and
again, and will probably be told yet again in English story, and at last
when they had well-nigh given up to despair they heard the sound
of English guns, so different from the explosions of the long Danes,
and presently there was the call of the bugles, and out into the open
trotted a little fox terrier, the advance guard of the men who had
come to save Kumasi.
And now the change. Kumasi has a train from the coast port of
Sekondi every day, it has a population that exceeds that of the
capital of the Gold Coast itself, every day the forest is receding and
in the streets are growing up great buildings that mark only the
beginning of a trade that is already making the wise wonder how it
was when wealth lay on the ground for the picking up, England, who
had it all within her grasp, was amiable enough to allow the greater
portion of this wonderful land to fall to the lot of the French and
Germans.
The forest used to close Kumasi in on every side. It is set in a
hollow, and the tall trees and luxuriant green in the days that I have
just spoken of threatened to overwhelm it. Now that sensation has
passed away. Whatever Kumasi may be in the future, to-day it is a
busy centre of life and trade. Where the fetish tree stood, the
ground beneath its branches soaked with human blood and strewn
with human bones, is now the centre of the town where the great
buildings of the merchant princes of West Africa are rising. They are
fine, but they are a blot on the landscape for all that. The nation
that prides itself on being the colonising nation of the earth never
makes any preparation for the expansion of its territory or the
growth of its trade, so here in this conquered country, bought at the
cost of so much sweat and blood, the authorities are allowing to go
up, in the very heart of the town buildings, very handsome buildings
without doubt, so close together that in a tropical land where fresh
air is life itself they are preparing to take toll of the health of the
unfortunates who will have to dwell and work there. But beyond that
one grave mistake Kumasi promises to be a very pretty place as well
as a very important one. Its wide, red roads, smooth and well-kept,
are planted with trees, mangoes and palms; its bungalows are set
well apart, surrounded by trees and shrubs and lawns, their red-
brown roofs and verandahs toning picturesquely with the prevailing
green.
Curious it is when one thinks of its history to see the white painted
sign-posts on which are recorded the names of the streets. There is
“Kingsway” for one, and “Stewart-avenue,” after the man who
deeply loved the country, for another, and there are at least two
great roads that lead away to the fruitful country in the north, roads
that push their way through the dense forest and must even compel
the admiration of our friends the Germans, those champion road-
makers. And down those roads comes all the wonderful trade of
Kumasi, not as the trade of London, of course, but as the trade of
London was, perhaps, when Augustus ruled at Rome. The trade of
the world comes to London nowadays, the trade of the back-country
came to London then, and so does the trade of all the country round
come to the Ashanti capital. Its streets are thronged with all manner
of peoples, dark, of course, for the ruling whites are but an
inconsiderable handful, and only the Chief Commissioner and one
missionary have been daring enough to bring their wives.
Ashanti is a conquered country, and it seems to me it has got just
the right sort of Government, a Government most exactly suited to
the requirements of the negro in his present state of advancement.
What a negro community requires is a benevolent despotism, but as
a rule the British Government, with its feeling for the rights of the
individual, does not see its way to give it such a Government. But
Ashanti was conquered at great cost, wherefore as yet England has
still to think of the rights of the white men who dwell there as
against the rights of the black man, and the result to me, an
onlooker, appears to be most satisfactory for both white and black.
Of course, such a Government requires to administrate not only
excellent men, not only honest and trustworthy men, but men who
have the interests of the country at heart, and who devote
themselves to it, and such men she has got in the Chief
Commissioner, Mr Fuller, and the subordinates chosen by him. Only
an onlooker am I, a woman, a passer-by, but as a passer-by I could
not but be struck by the difference between the feeling in the Gold
Coast Colony and the feeling in Ashanti. The whole tone of thought
was different. Everywhere on the Gold Coast men met me with the
question, “What did I think of this poisonous country? Wasn't it a
rotten place?” and they seemed bitterly disappointed if I did not
confirm their worst blame.
But in Ashanti it was different. The very clerks in the mercantile
houses had some good word to say for the country, and were
anxious that I should appreciate it and speak well of it, and this I
can but set down to the example and guidance of such men as the
Chief Commissioner and the men he chooses to serve under him.
Had the rest of West Africa always had such broad-minded, clever,
interested men at the head of affairs, I think we should have heard a
great deal less about its unhealthiness and a great deal more about
the productiveness of the country. Since I have seen German
methods I am more than thankful that I have been to Ashanti and
learned that my own country is quite equal to doing as well, if not
beating them at their own methods. The Ashanti himself, the
truculent warrior of ten years ago, has under the paternal and
sympathetic Government of this Chief Commissioner become a man
of peace. If he has not beaten his long Dane gun into a ploughshare
he has at least taken very kindly to trade and is pleased, nay eager
that the white man should dwell in his country. He stalks about
Kumasi in his brightly coloured, toga-like cloth still, very sure that he
is a man of great importance among the tribes, and his chiefs march
through the streets in chairs on men's heads, with tom-toms
beating, immense gaily coloured umbrellas twirling, their silken'
cloths a brilliant spot in the brilliant sunshine, their rich gold
ornaments marking them off from the common herd, and all their
people who are not Christian still give them unquestioned devotion.
But Kumasi, as I said, is the centre of a great trade, and the native
town, which is alongside but quite apart from the European town, is
packed with shops, shops that are really very much in the nature of
stalls, for there are no fronts to them, and the goods are exposed to
the street, where all manner of things that are attractive to the
native are set out.
And here one gathers what is attractive to the native. First and
foremost, perhaps, are the necessities of life, the things that the
white man has made absolute necessaries. First among them, I
think, would be kerosene and bread, so everywhere, in market-place
and shop, or even just outside a house, you may see ordinary wine
and whisky bottles full of kerosene, and rows and rows of loaves of
bread. Then there comes men's clothing—hideous shirts and uglier
trousers, tourist caps that are the last cry in hooliganism, and boots,
buttoned and shiny, that would make an angel weep. Alas! and alas!
The Ashanti in his native state, very sure of himself, has a certain
dignity about him even as must have had the old Roman. You might
not have liked the old Roman, probably you would not unless he
chose to make himself pleasant, but you could not but recognise the
fact that he was no nonentity, and so it is with the Ashanti till he
puts on European garments. Then how are the mighty fallen! for like
all negroes, in the garb of civilisation, he is commonplace when he is
not grotesque. What they are to wear I cannot say, but the better-
class among them seem to realise this, for I have often heard it said,
not only in Ashanti but in other parts of the Coast: “The Chief may
not wear European clothes.”
And beside clothes in the native shops are hurricane lanterns,
ordinary cheap kerosene lamps, and sewing machines which the
men work far more often then the women, accordions, mouth
harmoniums, and cotton goods in the strange and weird patterns
that Manchester thinks most likely to attract the native eye. I have
seen brooms and brushes and dustpans printed in brilliant purple on
a blue ground, and I have seen the outspread fingers of a great
hand in scarlet on a black ground. But mostly there is nothing of
very great interest in these shops, just European goods of the
commonest, cheapest description supplied apparently with the view
of educating the native eye in all that is ugliest and most
reprehensible in civilisation.
There are horses in Kumasi, for the forest and undergrowth have
been cleared away sufficiently to destroy the tsetse fly, and so most
evenings, when the heat of the day has passed, the Chief
Commissioner and his wife go for a ride, and on occasions many of
the soldiermen play polo and hold race-meetings, but as yet there is
no wheeled traffic in the streets. Most of the goods are carried on
men's heads, and the roadways are crowded. There are women with
loads on their heads and generally children on their backs, walking
as if the world belonged to them, though in truth they are little
better than their husbands' slaves. There are soldiers all in khaki,
with little green caps like condensed fezes, lor the place is a great
military camp and the black soldier swaggers through the street;
there are policemen in blue uniforms with red fezes, their feet bare
like those of the soldiers, and their legs bound in dark-blue putties;
and there are black men from all corners of West Africa. There are
the Kroo boys, those labourers of the Coast, with the dark-blue
freedom mark tattooed on their foreheads, never carrying anything
on their heads, but pushing and pulling heavily laden carts, in gangs
that vary from four to a dozen, and their clothing is the cast-off
clothing of the white man; there are Hausas and Wangaras, than
whom no man can carry heavier loads, and they wear not a flowing
cloth like the Ashanti, but a long, shirt-like garment not unlike the
smock of the country labourer. It is narrower and longer, but is
usually decorated with the same elaborate needlework about the
neck and shoulders; if their legs are not bare they wear Arab
trousers, full above and tight about their feet, and the flapping of
their heelless slippers makes a clack-clack as they walk. There are
Yorubas, dressed much the same, only with little caps like a child's
Dutch bonnet, and there are even men from the far north, with blue
turbans and the lower part of their faces veiled. Far beyond the
dense forest lies their home, away possibly in French territory, but
the trade is coming to this new city of the Batouri, and they wander
down with the cattle or horses. For all the cattle and horses come
down through the forest, driven hastily and fast because of the
deadly tsetse, and many must perish by the way. A herd of the
humped, long-horned cattle come wearily through the streets.
Whatever they may have been once, there is no spirit left in them
now, for they have come down that long road from the north; they
have fed sparely by the way, and they are destined for the feeding of
the population that are swarming into Kumasi to work the mines in
the south.
Three towns are here in Kumasi: the European quarter, the
Ashanti town, and the Mohammedan town or zonga. Here all the
carrying trade that is not done by Government is arranged for—by a
woman. Here the houses are small and unattractive, nondescript
native huts built by people who are only sojourners in the land,
come but to make money, ready to return to their own land in the
north the moment it is made. And they sit by the roadside with little
things to sell. Food-stuffs often, balls of kenki white as snow, yams
and cassada, which is the root of which we make tapioca, cobs of
Indian corn, and, of course, stink-fish that comes all the way from
the Coast and is highly prized as a food, and does not appear to
induce ptomaine poisoning in African stomachs. Some of these
dainties are set out on brass trays made in Birmingham; others on
wooden platters and on plates delicately woven in various patterns
of grass dyed in many colours. But most things they have they are
ready to sell, for the negro has great trading instincts, and that
trading instinct it is that has made him so easy to hold once he is
conquered.
Kumasi is peaceful enough now, and the only reminder of the bad
days of ten years back is the fort just above the native town, but it
looks down now across a smooth green lawn, on which are some
great, shady trees, where chiefs assembled whom I photographed.
One was a great fetish chief with gold ornaments upon his head and
upon his feet, and knowledge of enough magic, had this been the
fifteenth century instead of the twentieth, to drive the white man
and all his following back to the sea from whence he came; but it is
the twentieth, and he is wise enough to know it, and he flings all the
weight of his authority into the scales with the British raj. But at the
gate of the fort still stands a guard of black soldiers in all the glory
of scarlet and yellow which stands for gold, for the Chief
Commissioner lives here, and in a land where a chief is of such
importance it is necessary to keep up a certain amount of state, and
the Chief Commissioner ruling over this country and receiving
obeisance from the chiefs, clad in their gorgeous silken cloths, laden
with golden jewellery, men looked up to by their followers as half-
divine, must feel something like a Roman proconsul of old carrying
the eagles into savage lands, and yet allowing those savages as far
as possible to govern themselves by their own laws. Africa has
always been the unknown land, but now at last the light is being let
into dark places, the French have regenerated Dahomey, and the
railway comes to Kumasi. I sat on that verandah and thought of the
old days that were only ten years back, and learned much from the
Commissioner, and I felt that civilisation was coming by leaps and
bounds to Ashanti, and if it be true, as old tradition has it, that a
house to be firmly built must have a living man beneath its
foundation stone, then must the future of Kumasi be assured, for its
foundations were well and truly laid in rivers of human blood.
CHAPTER XXIII—IN THE HEART OF
THE RUBBER COUNTRY
Bound for Sunyani—The awe-inspiring-forest—The road through
the forest—The people upon that road—Ofinsu and an Ashanti house
—Rather a public bedroom—Potsikrom—A night of fear—Sandflies—
Attractive black babies—A great show at Bechem—A most important
person—The Hausa who went in fear of his life—Coronation night at
Tanosu—A teetotal party—The medical officer's views on trees—
Beyond the road—Sunyani.
I
talked to the Commissioner, and those talks with him made me
want to go somewhere out into the wilds. Kumasi was beginning
to look strangely civilised to me. It was a great trading-centre,
and presently it would be as well known, it seemed to me, as
Alexandria or Cairo, or at the other end of the Continent, Buluwayo.
I should like to have gone into the Northern Territories, but the rainy
season was upon us, and if that did not daunt me—and it would not
have done so—I had to consider the time. I ought to be back in
London. I had intended to be away for six months, and now it was
close on eight since I had come out of the mouth of the Mersey.
“Go to Sunyani,” said the Chief Commissioner, “and go on to
Odumase, where the rising began at the beginning of the century.
You will be the first white woman to go there, and I think you will
find it worth your while.”
So I interviewed the head of the transport service, and by his
kindness was supplied with seventeen carriers, and one hot day in
June started north.
They had doubts, these kind friends of mine, about my capabilities
as a traveller, at least they feared that something might happen to
me while I was in their country, and they told me that a medical
officer was starting north for Sunyam that day and would go with
me.
I looked up the medical officer and found him in the midst of
packages that he was taking with him beyond civilisation to last for a
year. He was most courteous, but it seemed to me that he felt the
presence of a woman a responsibility, and I was so sure of myself,
hated to be counted a nuisance, that when he said he had intended
to go only as far as Sansu that night, I expressed my intention of
going on to Ofinsu, and hinted that he might catch me up next
morning if he could.
So by myself I set out into the heart of the rubber country north
of Kumasi. I was fairly beyond civilisation now. Ten years ago this
country was in open rebellion against English rule, and even now
there are no European stores there; there is no bread, no kerosene,
no gin—those first necessities of an oncoming civilisation; it was
simply the wild heart of the rubber country, unchanged for hundreds
of years. It has been known, but it has not been lightly visited. It
has been a country to be shunned and talked of with bated breath
as “the land of darkness.” The desert might be dared, the surf might
be ventured, the black man might be defied, but the gloom of the
forest the white man feared and entered not except upon
compulsion. The Nile has given up its secrets, the Sahara yields to
cultivation, but still in Africa are there places where the all-
conquering white man is dwarfed, and one of them is the great
forest that lies north of the capital of Ashanti.
Here we know not the meaning of the word forest. England's
forests are delightful woods where the deer dwell in peace, where
the rabbits scutter through the fern and undergrowth, and where the
children may go for a summer's holiday; in Australia are trees close-
growing and tall; but in West Africa the forest has a life and being of
its own. It is not a thing of yesterday or of ten years back or of fifty
years. Those mighty trees that dwarf all other trees in the world
have taken hundreds of years to their growth. When a slight young
girl came to the throne of England, capturing a nation's chivalry by
her youth and innocence, the mahogany and kaku and odoum trees
were old and staid monarchs of the forest. When the first of the
Georges came over from Hanover, unwelcome, but the nation's last
hope, they were young and slim but already tall trees stretching up
their crowns to the brilliant sunlight that is above the gloom, and
now at last, when the fifth of that name reigns over them, at last is
their sanctuary invaded and the seclusion that is theirs shall be
theirs no longer. For already the axe is laid to their roots, and
through the awe-inspiring forest runs a narrow roadway kept clear
by what must be almost superhuman labour, and along that
roadway, the beginning of the end, the sign that marks the peaceful
conquest of the savage, that marks also the downfall of the forest
though it is not even whispered among the trees that scorn them
yet, flows a perpetual stream of traffic, men, women, and children.
Backwards and forwards from the north to Kumasi and the sea they
come, and they bear on their heads, going north, corrugated iron
and cotton goods, kerosene, and flour, and chairs, all the trifles that
the advance of civilisation makes absolute necessaries; and coming
down they bring all in their season, hides, and heavy cakes of
rubber, and sticks of dried snails, and all the other articles of native
produce that a certain peace has made marketable along the way or
in the markets of Kumasi.
The spell was upon me the moment I left the town. That road is
like nothing else in the world. The hammock and the carriers were
dwarfed by the great roots and buttresses of the trees to tiny,
crawling ants, and overhead was a narrow strip of blue sky where
the sunlight might be seen, but only at noon did that sunlight reach
the roadway below. We travelled in a shadow pleasant in that heat;
and on either side, close on either side, were the great trees.
Looking down the road I could see them straight as a die, tall pillars,
white and brown; ahead of me and close at hand the mighty
buttresses that supported those pillars rose up to the height of
perhaps ten men before the tree was fairly started, a tall trunk with
branches that began to spread, it seemed to me, hundreds of feet
above the ground. And between those tree-trunks was all manner of
undergrowth, and all were bound and matted together with thickly
growing creepers and vines. It was impossible to step an inch from
that cleared path. There would be no getting lost in the bush, for it
would be almost impossible for the unpractised hand to get into the
bush. There is nothing to be seen but the brown, winding roadway,
the dense green of the undergrowth, and the trunks of the trees tall
and straight as Nelson's column and brown or white against the
prevailing green. And there are all shades of green, from that so
pale that it is almost golden to that so dark it is almost black, but
never a flower breaks the monotony, the monotony that is not
monotony but dignity, and the flowers of an English spring or an
autumn in Australia would but cheapen the forest of the Gold Coast.
There must have been orchids, for sometimes as I passed their rich,
sensuous smell would come to my nostrils, but I only knew they
were there by my sense of smell just as sometimes I smelt a strong
smell of mice, and knew, though I could not see them, that
somewhere in the depths of the gloom were hidden away a great
colony of fruitarian bats that would not come out into the daylight.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com