0% found this document useful (0 votes)
47 views77 pages

Computer Programming For Beginners Ray Yao 1st F3thinker Instant Download

The document is a guide titled 'Computer Programming For Beginners' by Ray Yao, aimed at teaching essential programming skills to novices. It includes crash courses on various programming languages such as PowerShell, Node.js, Django, Scala, Swift, and Perl, along with downloadable source code for practice. The book is not suitable for experienced programmers and emphasizes a step-by-step approach to learning programming concepts.

Uploaded by

fpntgiai619
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views77 pages

Computer Programming For Beginners Ray Yao 1st F3thinker Instant Download

The document is a guide titled 'Computer Programming For Beginners' by Ray Yao, aimed at teaching essential programming skills to novices. It includes crash courses on various programming languages such as PowerShell, Node.js, Django, Scala, Swift, and Perl, along with downloadable source code for practice. The book is not suitable for experienced programmers and emphasizes a step-by-step approach to learning programming concepts.

Uploaded by

fpntgiai619
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 77

Computer Programming For Beginners Ray Yao 1st

F3thinker download

https://ebookbell.com/product/computer-programming-for-beginners-
ray-yao-1st-f3thinker-12297804

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Computer Programming For Beginners A Stepbystep Guide Murali Chemuturi

https://ebookbell.com/product/computer-programming-for-beginners-a-
stepbystep-guide-murali-chemuturi-7380940

Computer Programming For Beginners And Cybersecurity 4 Manuscripts In


1 The Ultimate Manual To Learn Step By Step How To Professionally Code
And Protect Your Data This Book Includes Python Java C And
Cybersecurity Alan Grid
https://ebookbell.com/product/computer-programming-for-beginners-and-
cybersecurity-4-manuscripts-in-1-the-ultimate-manual-to-learn-step-by-
step-how-to-professionally-code-and-protect-your-data-this-book-
includes-python-java-c-and-cybersecurity-alan-grid-56901338

Computer Programming For Beginners What Are The Basics Of Programming


Computer Programming Is Quizlet Isaias Kohus Kohus

https://ebookbell.com/product/computer-programming-for-beginners-what-
are-the-basics-of-programming-computer-programming-is-quizlet-isaias-
kohus-kohus-27840410

Computer Programming For Starters Basic Easy Instructions Computer


Coding For Beginners Angelo Grochowski Grochowski

https://ebookbell.com/product/computer-programming-for-starters-basic-
easy-instructions-computer-coding-for-beginners-angelo-grochowski-
grochowski-27840412
C C For Beginners Crash Course Master C Programming Fast And Easy
Today Computer Programming Programming For Beginners Book 2 Raj Ali
Prx Publishings

https://ebookbell.com/product/c-c-for-beginners-crash-course-master-c-
programming-fast-and-easy-today-computer-programming-programming-for-
beginners-book-2-raj-ali-prx-publishings-36338794

Python Programming The Ultimate Crash Course For Learning Python


Quickly With Practical Examples And Coding Language Tricks For
Beginners Computer Programming For Data Science And Machine Learning
Daniel Howard
https://ebookbell.com/product/python-programming-the-ultimate-crash-
course-for-learning-python-quickly-with-practical-examples-and-coding-
language-tricks-for-beginners-computer-programming-for-data-science-
and-machine-learning-daniel-howard-52556516

Computer Programming For Absolute Beginners Learn Essential Computer


Science Concepts And Coding Techniques To Kickstart Your Programming
Career Joakim Wassberg

https://ebookbell.com/product/computer-programming-for-absolute-
beginners-learn-essential-computer-science-concepts-and-coding-
techniques-to-kickstart-your-programming-career-joakim-
wassberg-11734748

Learn Sql Basics Of Sql Computer Programming Concepts For Beginners


Lina Polly

https://ebookbell.com/product/learn-sql-basics-of-sql-computer-
programming-concepts-for-beginners-lina-polly-232354248

Computer Programming In C For Beginners Avelino J Gonzalez

https://ebookbell.com/product/computer-programming-in-c-for-beginners-
avelino-j-gonzalez-23397782
Computer

Programming

For Beginners
Quick Start Guide
Tutorial Book 3

Ray Yao
Copyright © 2015 by Ray Yao
All Rights Reserved
Neither part of this book nor whole of this book may be reproduced or
transmitted in any form or by any means electronic, photographic or
mechanical, including photocopying, recording, or by any information
storage or retrieval system, without prior written permission from the
author. All rights reserved!
Ray Yao

About the Author: Ray Yao


Certified PHP engineer by Zend, USA
Certified JAVA programmer by Sun, USA
Certified SCWCD developer by Oracle, USA
Certified A+ professional by CompTIA, USA
Certified ASP. NET expert by Microsoft, USA
Certified MCP professional by Microsoft, USA
Certified TECHNOLOGY specialist by Microsoft, USA
Certified NETWORK+ professional by CompTIA, USA
www . amazon . com/author/ray-yao
Preface
“Computer Programming” covers all essential computer language
knowledge. You can learn complete primary skills of computer
programming fast and easily.
The book includes six crash courses, such as PowerShell, Node.js, Django,
Scala, Swift, Perl.

Note:
This book is only for computer programming beginners, it is not suitable
for experienced computer programmers.

Source Code for Download


This book provides source code for download; you can download the
source code for better study, or copy the source code to your favorite
editor to test the programs.
Table of Contents

PowerShell
Hour 1 Introduction
Hour 2 Basics
Hour 3 Operators
Hour 4 Statement
Hour 5 Function
Hour 6 String
Hour 7 Object
Hour 8 Pipeline
Appendix 1
Appendix 2
Source Code Download

Node.Js
Hour 1 Introduction
Hour 2 Basics
Hour 3 Event
Hour 4 Write/Read
Hour 5 Stream
Hour 6 File
Hour 7 Operations
Hour 8 Modules
Appendix
Source Code Download

Django
Hour 1 Introduction
Hour 2 Basics
Hour 3 Django Tags
Hour 4 Models
Hour 5 Form/Method
Hour 6 Administration Tool
Appendix 1
Python Basic
Appendix 2
Texts & Answers
Source Code Download

Scala
Hour 1 Introduction
Hour 2 Basics
Hour 3 Operators
Hour 4 Statement
Hour 5 Methods
Hour 6 Arrays
Hour 7 Collection
Hour 8 Class/Object
Appendix 1
Appendix 2
Source Code Download

Swift
Hour 1 Introduction
Hour 2 Basics
Hour 3 Operators
Hour 4 Statements
Hour 5 String/Array
Hour 6 Collection
Hour 7 Class/Object
Hour 8 Operations
Q&A
Source Code Download

Perl
Hour 1 Introduction
Hour 2 Basics
Hour 3 Hash
Hour 4 Statement
Hour 5 Operations
Hour 6 Files
Hour 7 Functions
Hour 8 Class/Object
Appendix
Perl Q & A
Source Code Download

Source Code Download


PowerShell
Hour 1
Introduction
What is PowerShell?
PowerShell is a command-line script environment running on a Windows
machine for automate system and application management. You can think of
it as an extension of the command line prompt cmd. exe. PowerShell is built
on the. net platform, and all that are passed by the command are . net objects.
PowerShell fully supports the use of objects. It is readable, easy to use, and
powerful. From Window 7 to now, various operating systems have built-in
PowerShell platforms.
Currently there are five versions of PowerShell:
Operating Systems Versions:
Windows Vista or Windows Server 2008 PowerShell 1 . 0
Windows 7 or Windows Server 2008 R2 PowerShell 2 . 0
Windows 8 or Windows Server 2012 PowerShell 3 . 0
Windows8 . 1 or Windows Server 2012 R2 PowerShell 4 . 0
Windows 10 or Windows Server 2016 PowerShell 5 . 0
On August 18, 2016, Microsoft announced that the open source, cross-
platform version of PowerShell will support multiple operating systems
including Windows, MacOS, CentOS and Ubuntu. It is called “PowerShell
Core” and runs on . net Core.
Start PowerShell

Method 1:
Click Start > Windows PowerShell

Method 2:
Click Start > Type “PowerShell” in the Search field.

Method 3:
Click Start > Type “PowerShell” in the Run field.

Method 4:
Click Start > All Programs > Accessories > Windows PowerShell.

After you start the PowerShell, you can see a blue screen.
PowerShell Commands
The format of Powershell command is “verb - noun”.
The syntax to check the PowerShell commands is as follows:
Get-Command

Example 1.1
PS C:\Users\RAY> Get-Command

CommandType Name
----------- ----
Alias Add-ProvisionedAppxPackage
Alias Apply-WindowsUnattend
……

Explanation:
CommandType: There are three command types in PowerShell:
1. Alias: another name of the command.
2. Function: the command is used for a function.
3. Comlet: a powerful PowerShell command, its parameter is a . net
object.
Note:
1 . For easier reading, we will omit “PS C:\Users\RAY> ” in later pages
.
2 . The PowerSell commands will be shown in bold type in later pages .
Get Command Alias
The syntax to get the command alias is as follows:

Get-Command -CommandType Alias

Example 1.2

Get-Command -CommandType Alias

CommandType Name
----------- ----
Alias % -> ForEach-Object
Alias ? -> Where-Object
Alias ac -> Add-Content
…..

Explanation:
The alias of the “ForEach-Object” is %.
The alias of the “Where-Object” is ?
The alias of the “Add-Content” is ac
By the way, the alias of the “Get-Command” is gcm.
Note:
1 . For easier reading, we will omit “PS C:\Users\RAY> ” in later pages
.
2 . The PowerSell commands will be shown in bold type in later pages .
Get Commands with Verb
The syntax to get some commands with the specified verb is as follows:

Get-Command –verb Specified-Verb

Example 1.3

Get-Command -verb Clear

CommandType Name
----------- ----
Function Clear-BitLockerAutoUnlock
Function Clear-Disk
Function Clear-DnsClientCache
Function Clear-FileStorageTier
Function Clear-Host
Function Clear-StorageDiagnosticInfo
Cmdlet Clear-Content
Cmdlet Clear-EventLog
Cmdlet Clear-History
……

Explanation: “Get-Command -verb Clear” gets the commands with


“Clear” verb.
Get Commands with Noun
The syntax to get some commands with specified noun is as follows:

Get-Command -noun Specified-Noun

Example 1.4

Get-Command -noun Service


CommandType Name
----------- ----
Cmdlet Get-Service
Cmdlet New-Service
Cmdlet Restart-Service
Cmdlet Resume-Service
Cmdlet Set-Service
Cmdlet Start-Service
Cmdlet Stop-Service
Cmdlet Suspend-Service
……

Explanation:
“Get-Command -noun Service” gets the commands with “Service” noun.
Command with * Character
The syntax to use * character in the command is as follows:
Get-Command verb-*
Get-Command *-noun

Example 1.5
Get-Command Set-*
CommandType Name
----------- ----
Function Set-ClusteredScheduledTask
Function Set-DAClientExperienceConfiguration
Function Set-DAEntryPointTableItem
……
“Get-Command Set-*” returns all commands beginning with “Set”
Example 1.6
Get-Command *-Service
CommandType Name
----------- ----
Cmdlet Get-Service
Cmdlet New-Service
Cmdlet Restart-Service
……
“Get-Command *-Service” retunrs all commands ending with “Service ” .
Help Command
The syntax to get help for a command is as follows:

Help Specified_Command

Example 1.7
Help Clear-Host

NAME
Clear-Host
SYNOPSIS
SYNTAX
Clear-Host [<CommonParameters>]
DESCRIPTION
RELATED LINKS
http://go. microsoft. com/fwlink/?LinkID=225747
REMARKS
To see the examples, type: "get-help Clear-Host -examples".
For more information, type: "get-help Clear-Host -detailed".
For technical information, type: "get-help Clear-Host -full".
For online help, type: "get-help Clear-Host -online"
……

Explanation: “Help Clear-Host” can help to know more about the


“Clear-Host” command in detail.
Man Command
Man is an alias of the Help commands.
The syntax to man a command is as follows:

Man Specified_Command

Example 1.8
Man Start-Process

NAME
Start-Process
SYNTAX
Start-Process [-FilePath] <string> [[-Argum
ring>] [-LoadUserProfile] [-NoNewWindow] [-
ing>] [-RedirectStandardOutput <string>] [-
Maximized}] [-UseNewEnvironment] [<CommonP
Start-Process [-FilePath] <string> [[-Argum
ring>] [-Wait] [-WindowStyle <ProcessWindow
ALIASES
saps
start
……

Explanation:
“Man” can know more about the “Man” command in detail.
Get Service
“Get-Service” command can know about the service the computer
provides.

Get-Service

Example 1.9
Get-Service
Status Name DisplayName
------ ---- -----------
Stopped AeLookupSvc Application Experience
Stopped ALG Application Layer Gateway Service
Running AlibabaProtect Alibaba PC Safe Service
Stopped AppIDSvc Application Identity
Running Appinfo Application Information
Stopped AppReadiness App Readiness
Running Audiosrv Windows Audio
Stopped AxInstSV ActiveX Installer (AxInstSV)
Stopped BaiduUpdater Baidu Updater
Stopped BDESVC BitLocker Drive Encryption Service
Running BFE Base Filtering Engine
Running BITS Background Intelligent Transfer Ser...
Running Browser Computer Browser
……

Explanation:
“Get-Service” can view the service in the current computer.
Arithmetical Operation
We can think of PowerShell as a calculator, input some numbers, add,
subtract, multiply, divide and mod, then press Enter key, and see the result.
Example 1.10

10 + 20 + 30
60
100 - 20
80
2 * 80
160
90 / 2
45
10 % 3
1

Explanation:
“+ , - , * , / , % ” are the arithmetical operators. After you press the Enter
key, you can see the result.
Execute external commands
PowerShell can run external commands as follows:
External Commands Usages
ipconfig Check network configuration
netstat Check network port status
route print Check route information
cmd Launch the CMD console
cmd /c help Check available CMD commands
exit Exit the CMD

Example 1.11
cmd /c help

For more information on a specific command, type HELP command-name


ASSOC Displays or modifies file extension associations.
ATTRIB Displays or changes file attributes.
BREAK Sets or clears extended CTRL+C checking.
……

Explanation:
“cmd /c help” can check the available CMD commands.
Create a PowerShell File
PowerShell has own its scripting file, its extension name is .psl
The syntax to create a PowerShell file is as follows:

echo “ file contents ” > name. psl

Example 1.12

echo "This is a PowerShell scripting file" > myfile.ps1

Explanation:
After input the above command, please press the Enter key.
“echo “ file contents ” > name. psl” creates a PowerShell file.
“This is a PowerShell scripting file” is the content of this PowerShell file.
“myfile. psl” is the file name of this PowerShell file.
View the PowerShell File
We can view the contents of the specified PowerShell file.
The syntax to view the contents of the PowerShell file is as follows:

Get-Content . / myfile. ps1

Example 1.13
echo "This is a PowerShell scripting file" > myfile.ps1
Get-Content ./myfile.psl

This is a PowerShell scripting file

Explanation:
“Get-Content . /myfile. psl” can show the content of the myfile. psl.
The output is “This is a PowerShell scripting file”.
“./ ” means the relative path.
Hour 2
Basics
Comment
PowerShell uses the # symbol as the comment mark. The PowerShell
compiler will ignore the contents of the comments.

# comment

Example 2.1
100 + 200 # add
300

100 - 30 # subtract
70

2 * 500 # multiply
1000

27 / 3 # divide
9

8%2 # mod
0

Explanation:
“#add, #subtract, #multiply, #divide, #mod” are PowerShell comments,
which are ignored by the PowerShell compiler.
Variable
Variables are used to hold data temporarily.
Define a variable:

$variable_name = value

Show the value of a variable:

$variable_name

Example 2.2
$x = 100 # define a variable
$y = 200 # define a variable
$z = 300 # define a variable
$x # show $x value
100
$y # show $y value
200
$z # show $z value
300
Variable Name
In PowerShell, variable names start with the dollar sign $, and the
remaining characters can be any alphanumer, underscore, and any letter.
PowerShell variable names are case-insensitive ($var and $VAR are the
same variable). Some special characters are generally not recommended to
work as variable names.
The following example will show the usages of some variables:
Example 2.3

$result=$a=$b=$c=100 # assign a value


$result # show the value
100

Example 2.4
$x=111
$y=222
$x,$y=$y,$x # exchange the values
$x
222
$y
111
Data Type
Any data has its own data type, we can use “gettype(). name” to check the
data type of a variable value.

(data). gettype(). name

Example 2.5

(100).gettype().name
Int32
(8888888888888888).gettype().name
Int64
(168.88).gettype().name
Double
("Go in 8 Hours").gettype().name
String
(Get-Date).gettype().name
DateTime

Explanation:
“(data). gettype(). name” can get the data type of various data.
Specify Data Type
We can specify a data type for a variable when defining a variable.

[type] $variable = value

Example 2.6
[int]$a=100.88
$a
101
[string]$b=200.99
$b.gettype().name
String

Explanation:
“[int]$a=100. 88” specifies an “int” type for the $a.
“[string]$b=200. 99” specifies a “string” type for the $b.
Date Time Type
To define a variable with Date Time type is as follows:

[Date Time] $variable = value

Example 2.7

[DateTime] $day=Get-Date
$day
7/4/2019 17:41:28
$day.DayOfWeek
Thursday
$day.DayOfYear
185

Explanation:
“[DateTime] $day” specifies Data Time type for the $day.
“Get-Date” gets the current date.
“$day. DayOfWeek” gets the current day in the week.
“$day. DayOfYear” gets the numbers of days in the year.
Create an Array
An array is a collection of variables with the same type and name. These
variables are called elements of an array, and each element has a number
called an index, also called key.
The syntax to create an array is as follows:

$array_name = element0, element1, element2, element3,…

Example 2.8

$myArray=100, 111, 112, 113


$myArray
100
111
112
113

Explanation:
“$myArray=100, 111, 112, 113” creates an array with four elements. Their
values are 100, 111, 112, 113.
The index of the first element is 0.
The index of the second element is 1.
The index of the third element is 2.
Polymorphic Array
The elements of the PowerShell array can be polymorphic, such as int
type, string type, date time type, or empty element.

(1) Create a different type array:

$array_name = int, “String”, (date type), …

Example 2.9

$myArray = 10, “Good”, (get-date)


$myArray # different type array
10
Good
7/4/2019 20:18:30

(2) Create an empty array:

$array_name = @()

Example 2.10

$myArray = @() # empty array


$myArray -is[array] # check if it’s a array
True
Access Array
The elements of an array can be indexed, with the first element having an
index of 0 , and the last element having an index of -1.
The syntax to access the array is as follows:

$array_name[ index ]

Example 2.11
$myArray=@()
$myArray -is[array]
True
$myArray = "C#","in","8", "Hours"
$myArray[0]
C#
$myArray[1]
in
$myArray[2]
8
$myArray[-1]
Hours

Explanation:
“$myArray[0]” accesses the first element “C#”.
“$myArray[-1]” accesses the last element “Hours”.
Array Element
(1) We can create an array by range.

$array_name = num1 .. num2

Example 2.12

$myArray = 100 .. 102 # 10 0 . . 102 is a range


$myArray
100
101
102

(2) We can append some elements to the array.

$array_name += "new_element"

Example 2.13
$myArray = "C++","in","8 Hours"
$myArray += "is a good book!" # append
$myArray
C++
in
8 Hours
is a good book!
Insert, Remove Element
To insert or remove Array elements in PowerShell, we need to convert the
Array object to an ArrayList object first. Because ArrayList objects have
Insert() and RemoveAt() methods, which can insert or delete array
elements.

$arraylist = $array # convert array object to arraylist object


$arraylist. Insert(index, element) # insert an element
$arraylist. Remove(index) # remove an element

Example 2.14
$myArray = 0..8
$arraylist = $myArray # convert
$arraylist.Insert(6,'100') # insert
$arraylist.RemoveAt(3) # remove
$arraylist
0
1
2 # remove an element “3”
4
5
100 # insert 100 before index 6
6
7
8
Clone Array
We can clone a specified array as another array.
The syntax to clone an array is as follows:
$array2 = $array1. Clone()

Example 2.15

$array1 = "AngularJS", "in", "8", "Hours"


$array2 = $array1.Clone()
$array2
AngularJS
in
8
Hours

Explanation:
“$array2 = $array1.Clone() ” clones an array “array1” as another array
“array2“.
Hour 3
Operators
Comparison Operators
PowerShell has following comparison operators:
Operators Descriptions
-eq equal
-ne not equal
-gt greater
-ge greater or equal
-lt less
-le less or equal
-contains includes
-noncontains not includes

Example 3.1
(6,7,8) -contains 3
False
(1,3,6 ) -contains 6
True
(0,2,5 ) -notcontains 4
True
8 -eq 6
False
"C" -eq "c"
True
"R" -ne "r"
False
10 -lt 100
True
100 -ge 100
True
Explanation:
-eq equal
-ne not equal
-gt greater
-ge greater or equal
-lt less
-le less or equal
-contains includes
-noncontains not includes
Logical Not
The operator of negation is -not or !
Operator Descriptions
- not logical not
! logical not

Example 3.2

$bool = 200 -gt 100


$bool
True
-not $bool
False
!($bool)
False

Explanation:
If $bool is equal to true, then –not $bool will return false.
If $bool is equal to true, then ! $bool will return false.
Boolean Operators
The following is PowerShell boolean operators:
Operators Descriptions
-and and
-or or
-not not

Example 3.3
$x = 1 # 1 represents true
$y = 0 # 0 represents false
$x -and $y
False
$x -or $y
True
Explanation:
true -and true; true -and false; false -and false;
returns true; returns false; returns false;
true or true; true or false; false or false;
returns true; returns true; return false;
Arithmetic Operators
The following is PowerShell arithmetic operators:
Operators Descriptions
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus

Example 3.4
$a = 20
$b = 10
$a + $b #addition
30
$a - $b #subtraction
10
$a * $b #multiplication
200
$a / $b #division
2
$a % $b #modulus
0
Assignment Operators
The following is PowerShell assignment operators:
Operators Meanings
a += b a=a+b
a -= b a=a-b
a *= b a=a*b
a /= b a=a/b
a %= b a=a%b

Example 3.5
$a = 30
$b = 10
$a += $b
$a
40
$a = 30
$b = 10
$a -= $b
$a
20
$a = 30
$b = 10
$a *= $b
$a
300
$a = 30
$b = 10
$a /= $b
$a
3
$a = 30
$b = 10
$a %= $b
$a
0
Explanation:
a += b means a = a + b
a -= b means a = a - b
a *= b means a = a * b
a /= b means a = a / b
a %= b means a = a % b
Increase / Decrease Operators
The syntax to use ++ or -- is as follows:
Operators Descriptions
++ Increase 1
-- Decrease 1

Example 3.6
$x = 10
$x++
$x
11
$y = 10
$y--
$y
9
Explanation:
“$x++” makes the value of $x increasing 1.
“$y--” makes the value of $y decreasing 1.
If-elseif-else
The syntax to use the condition statement is as follows:

If( condition ){ # if true, do this


}
elseif( condition ) { # if true, do this
}
else{ # if not true, do this
}

Example 3.7
$num=10
if ($num -gt 20) {"$num is greater than 20 " } else {"$num is less
than 20 "}
10 is less than 20
# “num –gt 20” is false, so the output is “10 is less than 20”.
Example 3.8

$n = +1
if($n -lt 0 ){"-1" } elseif($n -gt 0){"+1"}
+1

# “$n –gt 0” is true, so the output is “+1”


Example 3.9

$color = "yellow"
If( $color -eq "green" ){
"The color is green"
}
Elseif( $color -eq "yellow"){
"The color is yellow"
}
Elseif( $color -eq "red" ){
"The color is red"
}
Else{
"The color is white"
}

The color is yellow

Explanation:
The condition is equal to “yellow”, so the output is “The color is yellow”.
Switch Statement
The switch statement is just like a multiple If-elseif-else statement.

switch(<test_value>) {
<condition1> {<action>; break}
<condition2> {<action>; break}
<condition3> {<action>; break}
……
}
The test_value will compare each condition first, if equals one of the
“condition” value; it will execute that “action” code. “break;” terminates
the code running.

Example 3.10

switch(3){
1 {"One"; break}
2 {"Two"; break}
3 {"Three"; break}
4 {"Four"; break}
}

Three

Explanation:
The test_value is equal to 3, so it outputs “Three”.
Switch statement can be used to compare the strings.

Example 3.11
$book="Ruby"
switch($book){
"Html" {"Html in 8 Hours"; break}
"Ruby" {"Ruby in 8 Hours"; break}
"Java" {"Java in 8 Hours"; break}
"Rust" {"Rust in 8 Hours"; break}
}

Ruby in 8 Hours

Explanation:
The test_value is equal to “Ruby”, so it outputs “Ruby in 8 Hours”
Random documents with unrelated
content Scribd suggests to you:
Lucky and Unlucky Days.

So, there are days which are lucky and unlucky. A Persian couplet lays down that one
should not go east on Saturday and Monday; west on Friday and Sunday; north on
Tuesday and Wednesday; south on Thursday. Even Lord Burghley advised his son to be
cautious as regards the first Monday in April, when Cain was born and Abel slain; the
second Monday in August, when Sodom and Gomorrah were destroyed; the last Monday
in December, which was the birthday of Judas. Akbar laid down that the clothes which
came into his wardrobe on the first day of the month Farwardîn were unlucky.143 The
way some people get over omens of this kind is to send some article ahead of the
traveller on the unlucky day, which absorbs the ill omen, which would otherwise have
fallen upon him.

The catalogue of superstitions of this class might be almost indefinitely extended. The
principles on which most of them depend are clear enough. They rest on a sort of
sympathetic magic. Things which are good-looking, people who are healthy or
prosperous, give favourable omens, while those that are ugly, or of low caste, or
associated with menial or unpleasant duties, and so on, are ominous. Europeans in India
usually quite fail to realize the influence which such ideas exercise over the minds of the
people. Most of us have been struck by the almost unaccountable failure of natives to
attend a summons from the Courts, to keep an appointment to meet a European officer
for the inspection of a school or market. If inquiries are made it will often be found that
some idea of this kind explains the matter.

Thus, Colonel Tod describes how he had a visit from Mânik Chand. “He looked very
disconsolate and explained that he had seven times left his tent and as often turned back,
the bird of omen having each time passed him on the adverse side; but that at length he
had determined to disregard it, as having forfeited confidence he was indifferent to the
future.”144

The same idea of good or evil omen attaches to many places and persons. “Nolai was
built by Râja Nol. Its modern appellation of Barnagar has its origin in a strange, vulgar
superstition of names of ill omen, which must not be pronounced before the morning
meal. The city is called either Nolai or Barnagar, according to the hour at which the
mention becomes necessary.”145 So with the town of Jammu in Kashmîr, which is
unlucky from its association with Yama, the god of death; with Talwâra in the
Hoshyârpur District, which is connected with the sword (talwâr); with Rohtak, which
should be called Rustajgarh, and with numerous other places in Northern India. Thus, if
people want to speak of Bulandshahr in the morning they call it by the old Hindi name
of Unchgânw; Bhongânw in Mainpuri they call Pachkosa; Nânauta in Sahâranpur,
Phûtashahr; Mandwa in Fatehpur, Rotiwâla, and so on.146

So, there is hardly a village in which it is not considered ominous to name before
breakfast some one who, from his misery, rascality, or some other reason, is considered
unlucky. In Mathura there is a tank built by Râja Patni Mall.

“Should a stranger visit it in the morning and inquire of any Hindu by whom it was
constructed, he will have considerable difficulty in eliciting a straightforward answer.
The Râja, it is said, was of such a delicate constitution that he could never at any time
take more than a few morsels of the simplest food; hence arises the belief that any one
who mentions him the first thing in the morning will, like him, have to pass the day
fasting.”147 When we wonder at people suffering bondage of this kind, we must not
forget that similar beliefs prevail in our own country. “In Buckie there are certain family
names which no fisherman will pronounce. The ban lies particularly heavy on Ross.
Coull also bears it, but not to such a degree. The folks of that village talk of spitting out
the bad name.”148

A similar euphemistic form of expression is often used in regard to animals. If you are
civil and do not abuse the house rats, they will not damage your goods.149

The Mirzapur Patâris when they have to mention a monkey in the morning, call him
Hanumân, and the bear Jatari, or “he with the long hair,” or Dîmkhauiya, “he that eats
white ants.” The Pankas call the camel Lambghîncha or “long-necked.” “I asked the
Râja,” says Gen. Sleeman, “whether we were likely to fall in with any hares, making use
of the term Khargosh, or ‘ass-eared.’” “Certainly not,” said the Râja, “if you begin by
abusing them by such a name. Call them Lambkanna or ‘long-eared,’ and you will get
plenty.”

It is, of course, easy to avoid the effect of evil omens by the use of a little tact and wit, as
was the case with William the Conqueror, and there are many natives who are noted for
their cleverness in this way. Of an Eastern Sultân it is told that, leaving his palace on a
warlike expedition, his standard touched a cluster of lamps, called Surayya, because they
resembled the Pleiades. He would have turned back, but one of his officers said, “My
Lord! our standard has reached the Pleiades;” so he was relieved, advanced, and was
victorious.
Facilitating Departure of and Barring the Ghost.

We now come to consider the various means adopted to facilitate the journey of the
departing soul, and to prevent it from returning as a malignant ghost to bring trouble,
disease, or death on the survivors.

First comes the custom of placing the dying man on the ground at the moment of
dissolution. This is done partly, as we have seen, through some feeling of the sanctity of
Mother earth and that anyone resting on her bosom is safe from demoniacal agency, and
partly that the spirit may meet with no obstruction in its passage through the air. This last
idea prevails very generally. Thus, in Great Britain, death is believed to be retarded and
the dying person kept in a state of suffering by having any lock closed or any bolt shut in
the dwelling.150

The tortures which the soul undergoes in its journey to the land of the dead are vividly
pictured in some of the sacred writings.151 He is scorched by heat and pierced by wind
and cold, attacked by beasts of prey, stumbling through thorns and filth, until he at last
reaches the dread river Vaitaranî, which rolls its flood of abominations between him and
the other shore. So, when a Hindu dies, a lamp made of flour is placed in his hands to
light his ghost to the realm of Yama. Devout people believe that the spirit takes three
hundred and sixty days to accomplish the journey, so an offering of that number of
lamps is made. In order, also, to help him on his way, they feed a Brâhman every day for
a year; if the deceased was a woman, a Brâhmanî is fed. The lamps are lighted facing the
south, and this is the only occasion on which this is done, because the south is the realm
of death, and no one will sleep or have their house door opening towards that ill-omened
quarter of the sky.

With the same intention of aiding the spirit on his way, the relations howl during the
funeral rites, like the keeners at an Irish wake, in order to scare the evil spirits who
would obstruct the passage of the soul to its final rest.152

Another plan is to carry out the corpse by a special way, which is then barred up, so that
it may not be able to find its way back. The same end is attained by carrying out the
corpse feet foremost. Thus Marco Polo writes: “Sometimes their sorcerers shall tell them
that it is not good luck to carry the corpse out by the door, so they have to break a hole in
the wall, and to draw it out that way when it is taken to the burning.” It is needless to say
that the same custom prevails in Great Britain.153 The Banjâras of Khândesh reverse the
process. They move their huts after a death, and make a special entrance instead of the
ordinary door, which is supposed to be polluted by the passage of the spirit of the
dead.154 A somewhat similar custom prevails among the Maghs of Bengal. When the
friends return from the cremation ground, if it is the master of the house who has died,
the ladder leading up to the house is thrown down, and they must effect an entrance by
cutting a hole in the back wall and so creeping up.155 The theory appears to be that the
evil spirits who were on the watch for the ghost may be lurking near the route by which
the corpse was removed. We have the same idea in the European custom of saluting a
corpse which is being carried past. Grose distinctly states that the homage was really
offered to the attendant evil spirits.156 So, the Birhors of Bengal, on the sixth day after
birth, take the child out of the house by an opening made in the wall, so as to evade the
evil spirit on the watch at the door.157

The most elaborate precautions are, however, devoted to barring out the ghost and
preventing its return to its former home. The first of these consist of rules to prevent the
breach of the curiosity taboo. All through folk-lore we have instances of the danger of
looking back, as in the case of Lot’s wife. One of the maxims of Pythagoras was: “On
setting out on a journey, do not return back; for if you do the fairies will catch you.”158
In one of the Kashmîr tales the youth is warned not to look back, otherwise he would be
changed into a pillar of stone.159 In one of the Italian spells the officiant is told: “Spit
behind you thrice and look not behind you.”160 In an Indian tale the god promises to
help the Brâhman and to follow him. The Brâhman looks back and the deity becomes a
stone.161 The danger of looking back is that the person’s soul may be detained among
the ghosts of the dead. This is the reason why Hindu mourners do not look back when
they are returning from the cremation ground, and so we find that in Naxos it is a rule
that none of the women who follow the bier must look back, for if she do she will die on
the spot, or else one of her relations will die.162

Another means is to bar the return of the ghost in a physical way. Thus, when the
Aheriyas of the North-Western Provinces burn the corpse, they fling pebbles in the
direction of the pyre to prevent the spirit accompanying them. In the Himâlayas, when a
man has attended the funeral ceremonies of a relative, he takes a piece of the shroud
worn by the deceased and hangs it on some tree in the cremation ground, as an offering
to the spirits which frequent such places. On his return, he places a thorny bush on the
road wherever it is crossed by another path, and the nearest male relative of the
deceased, on seeing this, puts a stone on it, and pressing it down with his feet, prays the
spirit of the dead man not to trouble him.163 Among the Bengal Limbus, the Phedangma
attends the funeral, and delivers a brief address to the departed spirit on the general
doom of mankind and the succession of life and death, concluding with the command to
go where his fathers have gone, and not to come back to trouble the living with
dreams.164

Practically the same custom still prevails in Ireland. When a corpse is carried to the
grave, it is the rule for the bearers to stop half-way while the nearest relatives build up a
small monument of loose stones, and no hand would dare to disturb this monument
while the world lasts.165

In the case of the Dhângars and Basors, both menial tribes in the North-Western
Provinces, we come across an usage which appears to be of a very primitive type and to
be intended to secure the same object of barring the return of the ghost. After they have
buried the corpse they return to the house of the dead man, kill a hog, and after
separating the limbs, which are cooked for the funeral feast, they bury the trunk in the
courtyard of the house, making an invocation to it as the representative of the dead man,
and ordering him to rest there in peace and not worry his descendants. In the grave in
which they bury this they pile stones and thorns to keep the ghost down.

Many other mourning customs appear to be based on the same principle. Thus, the old
ritual directs that all who return from a funeral must touch the Lingam, fire, cowdung, a
grain of barley, a grain of sesame and water—“all,” as Professor De Gubernatis says,
“symbols of that fecundity which the contact with a corpse might have destroyed.”166
The real motive is doubtless to get rid of the ghost, which may have accompanied the
mourners from the cremation ground. In Borneo rice is sprinkled over them with the
same object, and the Basutos who have carried a corpse to the grave have their hands
scratched with a knife and magic stuff is rubbed into the wound to remove the ghost
which may be adhering to them.167

In Upper India, among the lower Hindu castes, when the mourners return after the
ceremony, they bathe, water being a scarer of ghosts, and at the house door they touch a
stone, cowdung, iron, fire, and water, which have been placed outside the house in
readiness when the corpse was removed. They then touch each their left ears with the
little finger of the left hand, chew leaves of the bitter Nîm tree as a sign of mourning,
and, after sitting some time in silence, disperse. Others, as the Ghasiyas, pass their feet
through the smoke of burning oil, and others merely rub their feet with oil to drive away
the ghost. The same idea of barring the return of the ghost by means of fire is found
among the Nats of Kâthiâwâr, who burn hay on the face of the corpse before cremating
it, and among the Thoris, who brand the great toe of the right foot of the deceased.168

This sitting in silence after the funeral is commonly explained merely as a mark of
sympathy for the bereaved relatives, but an analogous custom in Ireland leads to the
inference that the real reason may be to give the ghost time to depart, and not to interrupt
in any way its progress to the spirit land. On the west coast of Ireland, after the death no
wail is allowed to be raised until three hours have elapsed, because the sound of the
crying would hinder the soul from speaking to God when it stands before Him, and
would waken up the great dogs that are watching for the souls of the dead to devour
them.169
We have in these rites and in the ordinary ritual some further illustrations of the
protective influence of various articles which scare evil spirits. Thus, after the cremation
the officiating Brâhman touches fire and bathes in order to purify himself and bar the
return of the ghost; and the relative who lights the funeral pyre keeps a piece of iron with
him, and goes about with a brass drinking vessel in his hand as a preservative against
evil spirits while the period of mourning lasts. The system of protection is exactly the
same as in the case of the young mother and her child during the period of impurity
consequent on parturition. As the Hedley Kow, the North British goblin, is peculiarly
obnoxious at childbirth, so the Râkshasî of Indian folk-lore carries off the baby if the
suitable precautions to repel her are neglected.170

Another method of barring the ghost is to bury the dead face downwards. This is
common among sweepers of Upper India, whose ghosts, as seen in the probable
connection of the Chûhra and the Churel, are always malignant. The same custom
prevails among the Châran Banjâras of Khândesh. With this may be contrasted the Irish
custom of loosening the nails of the coffin before interment, in order to facilitate the
passage of the soul to heaven.171

A more elaborate ritual is that performed by the Mangars of Bengal. “One of the
maternal relatives of the deceased, usually the maternal uncle, is chosen to act as priest
for the occasion, and to conduct the ritual for the propitiation of the dead. First of all he
puts in the mouth of the corpse some silver coins and some coral, which is much prized
by the Himâlayan races. Then he lights a wick soaked in clarified butter, touches the lips
with fire, scatters some parched rice about the mouth, and, lastly, covers the face with a
cloth. Two bits of wood about three feet long are set up on either side of the grave. In the
one are cut nine steps or notches, forming a ladder for the spirit of the dead to ascend to
heaven; on the other every one present at the funeral cuts a notch to show that he has
been there. As the maternal uncle steps out of the grave, he bids a solemn farewell to the
dead and calls upon him to ascend to heaven by the ladder prepared for him. When the
earth has been filled in, the stick notched by the funeral party is taken away to a distance
and broken in two pieces, lest by its means the dead man should do the survivors a
mischief. The pole used to carry the corpse is also broken up, and the spades and ropes
are left in the grave.”172

Among other devices to bar the return of the spirit may be noted the custom after a death
in the family of preparing a resting-place for the ghost, until on the completion of the
prescribed funeral rites it is admitted to the company of the sainted dead. Thus, among
high-caste Hindus a jar of water is hung on a Pîpal tree for the refreshment of the spirit.
The lower castes practise a more elaborate ritual. When the obsequies are completed
they plant by the bank of a tank a bunch of grass, which the chief mourners daily water
until the funeral rites are over. In Bombay Mr. Campbell writes:173 “With a few
exceptions generally among almost all classes of Hindus, when the dead is carried to the
burning ground, on nearing the cemetery, a small stone is picked up and applied to the
eyes, chest, and feet of the deceased. This stone is called Jivkhâda or the spirit stone, is
considered as the representative or type of the deceased, and offerings of milk and water
are given to it for ten days.” Further he says: “On nearing the burning ground a small
stone is picked up, and with it the feet, nose, and chest of the deceased are touched
thrice. This stone is called Ashma, and is considered as a type of the deceased, and to it
funeral oblations are offered for ten days. The bier is then put down, and a ceremony
called Visrânti Srâddha is performed by the chief mourner, who comes forward and
offers two balls of rice, called Bhût or ‘spirit,’ and Khechar, or ‘roamer in the sky,’ to the
deceased. A hole is dug and the balls are buried there, and the litter is raised again on
shoulders by four persons and carried to the cemetery.”

The same idea of barring the return of the ghost accounts for the tombstone and cairn.
British evil spirits have been secured in this way. Mr. Henderson tells of a vicious spirit
which was entombed under a large stone for the space of ninety years and a day. Should
any luckless person sit on that stone, he would be unable to leave it for ever.174 In India,
when a Ho or Munda dies, a very substantial coffin is constructed and placed on faggots
of brushwood. The body, carefully washed and anointed with oil, is reverently laid in
this coffin, and all the clothes, ornaments, and agricultural implements that the deceased
was in the habit of using are placed with it, and also any money that he had with him
when he died. Then the lid of the coffin is put on and the whole is burned. The bones are
collected, taken in procession to the houses of friends, and every place where the
deceased was in the habit of visiting. They are finally buried under a large slab, and a
megalithic monument is erected to the memory of the dead. A quantity of rice is thrown
into the grave with other food.175

This custom of parading the corpse also prevails in Ireland.

“I believe it is the custom in most, if not all, small towns in the south for a body to be
carried, on its way to the graveyard, round the town by the longest way to bid its last
farewell to the place. If the body be that of a murdered man, it is, if possible, carried past
the house of the murderer. In county Wicklow, if an old church lies on the way to the
grave, the body is borne round it three times.”176

The Korkus of Hoshangâbâd have a remarkable method of laying the ghost. “Each clan
has a place in which the funeral rite of every member of that clan must be performed;
and however far the Korku may have wandered from the original centre of his tribe, he
must return there to set his father’s spirit to rest, and enable it to join its own family and
ancestral ghosts. In this spot a separate stake (munda) is set up for every one whose rites
are separately performed, and if a poor Korku performs them for several ancestors at
once, he still puts up only one stake. It stands two or two and a half feet above the
ground, planed smooth and squared at the top; on one side is carved at the top the
likeness of the sun and moon, a spider, and a wheat ear, and below it a figure
representing the principal person in whose honour it is put up, on horseback, with
weapons in his hands. If more than one person’s death is being celebrated, the rest are
carved below as subordinate figures. I could not learn that the spirits are supposed to
specially haunt this grove of stakes, or that Korkus have any dread of going near it at
night; but they are far bolder than Hindus in this respect. When the funeral rite is to be
performed, the first thing is to cut a bamboo and take out the pith, which is to represent
the bones of the deceased, unless he has been burnt, in which case the bones themselves
will have been preserved. A chicken is then sacrificed at the grave, and all that night the
mourners watch and dance, and sing and make merry.

“Next day they go out very early, and cut down some perfectly unblemished tree, either
teak or Salâi, not hollow or decayed or marked with an axe, which they cut to make the
Munda stake. It is brought home at once and fashioned by a skilful man. In the afternoon
it is carried to the place where cattle rest outside the village at noontide, and is washed
and covered with turmeric like a bridegroom, and five chickens are sacrificed to it. It is
then brought home again, and the pith representing the bones is taken outside the village
and hung to some tree for safety during the night.” (The idea, as we have elsewhere seen,
is more probably to allow the ghost an opportunity of revisiting them.)

“All the friends and relations have by this time assembled, and this evening the chief
funeral dinner is given. Next day, the whole party set out for the place where the stakes
of their clan are set up, and after digging a hole and putting two copper coins in it, and
the bones of the deceased or the pith which represents them, they put the stake in and fix
it upright. Then they offer a goat or chickens to it, which are presently eaten close by,
and in the evening the whole party returns home.”177

All this ritual, carried out by one of the most primitive Indian tribes, admirably
illustrates the principles which we have been discussing. The obvious intention of the
custom is to provide a resting-place for the spirit of the dead man, so that it may no
longer be a source of danger to the survivors.

Similar customs prevail among other aboriginal races of the Central Provinces. In some
places they burn their dead and then erect platforms, at the corners of which they place
tall, red stones. In other places a sort of low square mound is raised over the remains of
the deceased, at the corners of which are erected wooden posts, round which thread is
wound to complete the sacred circle, and a stone is set up in the centre. Here offerings
are presented, as in the jungle worship of their deities, of rice and other grains, fowls or
sheep. On one occasion after the establishment of the Bhonsla or Marhâta Government
in Gondwâna a cow was offered to the manes of a Gond; but this having come to the
notice of the authorities, the relations were publicly whipped, and all were interdicted
from doing such an act again.
To persons of more than usual reputation for sanctity offerings continue to be presented
for many years after their decease. In the District of Bhandâra rude collections of coarse
earthenware in the form of horses may be seen, which have accumulated from year to
year on the tombs of such men.178 The Pauariyas of Chota Nâgpur bury their dead,
except the bodies of their priests, which are carried on a cot into the forests covered with
leaves and branches and kept there, the reason assigned being that if laid in the village
cemetery their ghosts become very troublesome. The bodies of people who die of
contagious disease are similarly disposed of, the fact of death in this way being supposed
to be the direct act of one of the deities who govern plagues.179

In a country where immediate burial or cremation is necessary and habitual, we need not
expect to meet many examples of the customs, of which Mr. H. Spencer gives
examples,180 of placing the body on a platform or the like in order to secure its personal
comfort and conciliate the spirit. With the object of keeping a place ready for the spirit,
some tribes are careful to preserve the body. The Singpoo of the north-eastern frontier
keep the bodies of their dead chiefs for several years, and the Kûkis dry the dead at a
slow fire,181 practices which among more civilized races rise to embalming, as among
the Chinese and Egyptians. The Thârus of the sub-Himâlayan Tarâî have a custom of
placing the corpse on the village fetish mound during the night after death, and then the
mourning goes on. The practice is perhaps intended as much to prevent, by the sanctity
of the spot on which it is placed, the spirit from harming the survivors, as from any
special desire to conciliate it. Among all Hindus, of course, as far as exigencies of the
rapid disposal of the remains allow, it is habitual to treat the dead with respect; corpses
are carefully covered with red cloth, and removed reverently for burial or cremation.

There is also among some tribes the custom of disinterring corpses after temporary
burial. Thus, the Bhotiyas of the Himâlayas burn their dead only in the month of Kârttik;
those who die in the meantime are temporarily buried and disinterred when the season
for cremation arrives. The Kathkâris, a jungle tribe in Bombay, dig up the corpse some
time after burial and hold a wake over the ghastly relics. They appear to do this only in
the case of persons dying of cholera or small-pox, with some idea of appeasing the deity
of disease. In parts of Oudh the custom is said still to prevail among the lower castes
during epidemics, and it has recently attracted the attention of the sanitary officers.182

The Funeral Feast.

The funeral feast is evidently a survival of the feast when the dead kinsman was
consumed by his relatives, who wished thus to partake of the properties of the dead. By
another theory the feasting of the mourners is intended to resist the attempt of the ghost
of the dead man to enter their bodies, food being offensive to spirits.

Mutilation a Sign of Mourning.

Perhaps the only distinct survival of the ceremonial mutilation so common among
savages as a sign of mourning, is the shaving which is compulsory on all the clansmen
who shared in the death pollution. In the Odyssey, at the death of Antilochus, Peisistratus
says, “This is now the only due we pay to miserable men, to cut the hair and let the tear
fall from the cheek,” and at the burial rites of Patroklus “they heaped all the corpse with
their hair which they cut off and threw thereon.” The cutting of the hair is always a
serious matter. “Amongst the Maoris many spells were uttered at hair-cutting; one, for
example, was spoken to consecrate the obsidian knife with which the hair was cut;
another was pronounced to avert the thunder and lightning which hair-cutting was
believed to cause.”183 This ceremonial shaving is also perhaps the only survival in
Northern India of puberty initiation ceremonies. In some cases the hair cut appears to be
regarded as a sacrifice. Thus between the ages of two and five the Bhîls shave the heads
of their children. The child’s aunt takes the hair in her lap, and wrapping it in her clothes,
receives a cow, buffalo, or other present from the child’s parent.184

Respect Paid to Hair.

All over the world the hair is invested with particular sanctity as embodying the strength
of the owner, as in the Samson-Delilah story. Vishnu, according to the old story, took
two hairs, a white and a black one, and these became Balarâma and Krishna. Many
charms are worked through hair, and if a witch gets possession of it she can work evil to
the owner. An Italian charm directs, “When you enter any city, collect before the gate as
many hairs as you will which may lie on the road, saying to yourself that you do this to
remove your headache, and bind one of the hairs to your head.”185 The strength of Nisus
lay in his golden hair, and when it was pulled out he was killed by Minos. It is this
power of hair which possibly accounts for its preservation as a relic of the dead in
lockets and bracelets, or, as Mr. Hartland shows, the idea at the root of these practices is
that of sacramental communion with the dead.186
We have already come across instances of growing hair as a curse. Mr. Frazer gives
numerous examples of this custom among savage races, and in the Teutonic mythology
the avenger of Baldur will not cut his hair until he has killed his enemy.

In the folk-tales hair is a powerful deus ex machinâ, human hair for choice, but any kind
will answer the purpose. It is one of the most common incidents that the hero recognizes
the heroine by a lock of her hair which floats down the stream.187

A curious instance of mutilation regarded as a charm may be quoted from Bengal.


Should a woman give birth to several stillborn children, in succession, the popular belief
is that the same child reappears on each occasion. So, to frustrate the designs of the evil
spirit that has taken possession of the child, the nose or a portion of the ear is cut off and
the body is cast on a dunghill.

Food for the Dead.

Another means for conciliating the spirit of the dead man is to lay up food for its use.188
This is intended partly as provision for the ghost in its journey to the other world. But in
some cases it would seem that there is a different basis for the custom. As we have seen,
it is dangerous to eat the food of fairy-land, and unless food is supplied to the wandering
ghost, it may be obliged to eat the food of the lower world and hence be unable to return
to the world of men. According to the ancient Indian ritual it was recommended to put
into the hands of the dead man the reins of the animal killed in the funeral sacrifice, or in
default of an animal victim at least two cakes of rice or flour, so that he may throw them
to the dogs of Yama, which would otherwise bar his passage,189 and the same idea
constantly appears in the folk-tales where the hero takes some food with him which he
flings to the fierce beasts which prevent him from gaining the water of life or whatever
may have been the test imposed upon him. The use of pulse in the funeral rites depends
upon the same principle, and in the Greek belief the dead carried vegetables with them to
hell, either to win the right of passage or as provisions for the road.

Articles left with the Corpse.


Hence too comes the practice of burning with the corpse the articles which the dead man
was in the habit of using. They rise with the fumes of the pyre and solace him in the
world of spirits. The Kos told Colonel Dalton that the reason of this was that they were
unwilling to derive any immediate benefit by the death of a member of the family. Hence
they burn his wearing apparel and personal effects, but they do not destroy clothes and
other things which have not been worn. For this reason, old men of the tribe, in a spirit
of careful economy, avoid wearing new clothes, so that they may not be wasted at the
funeral.190

The custom of laying out food for the ghost still prevails in Ireland, where it is a very
prevalent practice during some nights after death to leave food outside the house, a
griddle cake or a dish of potatoes. If it is gone in the morning, the spirits must have taken
it, for no human being would touch the food left for the dead, as it might compel him to
join their company. On November Eve food is laid out in the same way.191

There are numerous examples of similar practices in India. The Mhârs of Khândesh,
when they remove a corpse, put in its mouth a Pân leaf with a gold bead from his wife’s
necklace. At the grave the brother or son of the dead man wets the end of his turban and
drops a little water on the lips of the corpse.192 So the Greeks used to put a coin in the
dead man’s mouth to enable him to pay his fare to Charon. In the Panjâb it is a common
practice to put in the mouth of the corpse the Pancharatana or five kinds of jewels, gold,
silver, copper, coral, and pewter. The leaves of the Tulasi or sweet basil and Ganges
water are put into the mouth of a dying man, and the former into the ears and nostrils
also. They are said to be offerings to Yama, the god of death, who on receiving them
shows mercy to the soul of the deceased. The same customs generally prevail among the
Hindus of Northern India.

Among the Buddhists of the Himâlaya, Moorcroft was present at the consecration of the
food of the dead.193 The Lâma consecrated barley and water and poured them from a
silver saucer into a brass vessel, occasionally striking two brass cymbals together,
reciting or chanting prayers, to which from time to time an inferior Lâma uttered
responses aloud, accompanied by the rest in an undertone. This was intended for the use
of the souls in hell, who would starve were it not provided. The music and singing, if we
may apply the analogy of Indian practices, are intended to scare the vagrant ghosts, who
would otherwise consume or defile the food.

The same is the case among the Drâvidian races. Thus, the Bhuiyârs of Mirzapur after
the funeral feast throw a cupful of oil and some food into the water hole in which the
ashes of the dead man are deposited. They say that he will never be hungry or want oil to
anoint himself after bathing. The Korwas, when burning a corpse, place with it the
ornaments and clothes of the deceased, and an axe, which they do not break, as is the
habit of many other savages. They say that the spirit of the dead man will want it to hack
his way through the jungles of the lower world. When the Bhuiyârs cremate a corpse
they throw near the spot an axe, if the deceased was a man, and a Khurpi or weeding
spud, if a woman. No one would dare to appropriate such things, as he would be forced
to join the ghastly company of their owners. Where the corpse is burned they leave a
platter made of leaves containing a little boiled rice, and they sprinkle on the ground all
the ordinary kinds of grain and some turmeric and salt as food for the dead in the next
world.

All these tribes and many low-caste Hindus in Northern India lay out platters of food
under the eaves of the house during the period of mourning, and they ascertain by
peculiar marks which they examine next day whether the spirit has partaken of the food
or not. Among the jungle tribes there is a rule that the food for the dead is prepared, not
by the house-mother, but by the senior daughter-in-law, and even if incapacitated by
illness from performing this duty, she is bound at least to commence the work by
cooking one or two cakes, the rest being prepared by one of the junior women of the
family.

Among the more Hinduized Majhwârs and Patâris we reach the stage where the clothes,
implements of the deceased, and some food are given to the Patâri priest, who, by
vicariously consuming them, lays up a store for the use of the dead man in the other
world. This is the principle on which food and other articles are given to the
Mahâbrâhman or ordinary Hindu funeral priest at the close of the period of mourning.

Among the Bengal tribes, the Mâl Pahariyas pour the blood of goats and fowls on their
ancestral memorial pillars that the souls may not hunger in the world of the dead. Among
the Bhûmij, at the funeral ceremony, an outsider, who is often a Laiya or priest, comes
forward to personate the deceased, by whose name he is addressed, and asked what he
wants to eat. Acting thus as the dead man’s proxy, he mentions various articles of food,
which are placed before him. After making a regular meal, he goes away, and the spirit
of the deceased is believed to go with him. So among the Kolis of the Konkan, the dead
man’s soul is brought back into one of the mourners. Among the Vârlis of Thâna, on the
twelfth day after death, a dinner is given to the nearest relations, and during the night the
spirit of the dead enters into one of the relations, who entertains the rest with the story of
some event in the dead man’s life. Among the Santâls, one of the mourners drums by the
ashes of the dead, and the spirit enters the body, when the mourner shaves, bathes, eats a
cock, and drinks some liquor.194

Among the Bengal Chakmas, a bamboo post or other portion of a dead man’s house is
burned with him, probably in order to provide him with shelter in the next world. Among
the Kâmis, before they can partake of the funeral feast, a small portion of every dish
must be placed in a leaf plate and taken out into the jungle for the spirit of the dead man,
and carefully watched until a fly or other insect settles upon it. The watcher then covers
up the plate with a slab of stone, eats his own food, and returns to tell the relatives that
the spirit has received the offering prepared for him.

The Fly as a Life Index.

The fly here represents the spirit, an idea very common in folk-lore, where an insect
often appears as the Life Index. An English lady has been known in India to stop playing
lawn-tennis because a butterfly settled in the court. In Cornwall wandering spirits take
the form of moths, ants, and weasels.195 We have the same idea in Titus Andronicus,
when Marcus, having been rebuked for killing a fly, gives as his reason,—

“It was a black, ill-favoured fly,


Like to the empress Moor; therefore I kill’d him.”

A fly is the guardian spirit of St. Michael’s well in Banff.196

Recalling the Ghost.

But while it is expedient by some or other of these devices to bar or lay the ghost, or
prevent its return by providing for its journey to, and accommodation in the next world,
some tribes have a custom of making arrangements to bring back the soul of the
deceased to the family abode, where he is worshipped as a household spirit. Some of the
Central Indian tribes catch the spirit re-embodied in a fowl or fish, some bring it home in
a pot of water or flour.197 Among the Tipperas of Bengal, when a man dies in a strange
village separated from his home by the river, they stretch a white string from bank to
bank along which the spirit is believed to return.198 This illustrates an idea common to
all folk-lore that the ghost cannot cross running water without material assistance.
Among the Hos on the evening of the cremation day certain preparations are made in
anticipation of a visit from the ghost. Some boiled rice is laid apart for it, and ashes are
sprinkled on the floor, in order that, should it come, its footsteps may be detected. On
returning they carefully scrutinize the ashes and the rice, and if there is the faintest
indication of these having been disturbed, it is attributed to the action of the spirit, and
they sit down shivering with horror and crying bitterly, as if they were by no means
pleased with the visit, though it be made at their earnest solicitation.199
Ashes.

This use of ashes as a means of identifying the ghost, constitutes in itself quite an
important chapter in folk-lore. It reminds us of the Apocryphal legend of Bel and the
Dragon. The idea probably originally arose from the respect paid to the ashes of the
house fire by primitive races, among whom the hearth and the kitchen are the home of
the household godlings.

There are numerous instances of this practice from Europe. In the Western Islands of
Scotland on Candlemas Day the mistress takes a sheaf of oats, dresses it in woman’s
apparel, and after putting it in a large basket beside which a wooden club is placed, cries
three times, “Briid is come! Briid is welcome!” Next morning they look for the
impression of Briid’s club in the ashes, which is an omen of a good harvest.200 Ash-
riddling is a custom in the northern counties. The ashes being riddled or sifted on the
hearth, if any one of the family be to die within the year, the mark of a shoe will be
impressed upon the ashes.201 In Wales they make a bonfire, and when it is extinguished
each one throws a white stone into the ashes. In the morning they search out the stones,
and if any one is found wanting, he that threw it will die within the year.202 In Manxland
the ashes are carefully swept to the open hearth and nicely flattened down by the women
before they go to bed. In the morning they look for footmarks on the hearth, and if they
find such footmarks directed to the door, it means in the course of the year a death in the
family, and if the reverse, they expect an addition to it by marriage.203 According to one
of the Italian charms, “And they were accustomed to divine sometimes with the ashes
from the sacrifices. And to this day there is a trace of it, when that which is to be divined
is written on the ashes with the finger or with the stick. Then the ashes are stirred by the
fresh breeze, and one looks for the letters which they form by being moved.”204

Amongst some Hindus, on the tenth night after the death of a person, he who fired the
funeral pyre is required to sift some ashes, near which a lamp is placed, and the whole
covered with a basket. Next morning the ashes are examined, and the ghost is supposed
to have migrated into the animal whose mark appears on the ashes.205 So, at the annual
feast of the dead, the jungle tribes of Mirzapur spread ashes on the floor, and a mark
generally like that of a chicken’s foot shows that the family ghosts have visited the
house. “On New Year’s Eve,” says Aubrey, “sift or smooth the ashes and leave it so
when you go to bed; next morning look, and if you find there the likeness of a coffin,
one will die; if a ring, one will be married.”206 In North Scotland, on the night after the
funeral, bread and water are placed in the apartment where the body lay. The dead man
was believed to return that night and partake of the food; unless this were done the
spirits could not rest in the unseen world. This probably accounts for the so-called “food
vases” and “drinking cups” found in the long barrows.207 All Hindus believe that the
ghosts of the dead return on the night of the Diwâlî or feast of lamps.

Replacing Household Vessels.

After a death all the household earthen pots are broken and replaced. It has been
suggested that this is due either to the belief that the ghost of the dead man is in some of
them, or that the custom may have some connection with the idea of providing the ghost
with utensils in the next world.208 In popular belief, however, the custom is explained by
the death pollution attaching to all the family cooking vessels, which, if of metal, are
purified with fire. The vessel is the home of the spirit: “At most Hindu funerals a water
jar is carried round the pyre, and then dashed to the ground, apparently to show that the
spirit has left its earthly home. So, the Surat Chondras set up as spirit homes large
whitewashed earthen jars laid on their sides. So, to please any spirit likely to injure a
crop, an earthen jar is set on a pole as the spirit’s house, and so at a wedding or other
ceremonies, jars, sometimes empty, sometimes filled with water, are piled as homes for
planets and other marriage gods and goddesses, that they may feel pleased and their
influence be friendly.”209

We have already met with the Kalasa or sacred jar. The same idea of the pollution of
earthen vessels prevailed among the Hebrews, when an earthen vessel remaining in a
tent in which a person died was considered impure for seven days.210

Funeral Rites in Effigy.

When a person dies at a distance from home, and it is impossible to perform the funeral
rites over the body, it is cremated in effigy. The special term for this is Kusa-putra, or
“son of the Kusa grass.” Colonel Tod gives a case of this when Râja Ummeda of Bûndi
abdicated: “An image of the prince was made, and a pyre was erected on which it was
consumed. The hair and whiskers of Ajît, his successor, were taken off and offered to the
Manes; lamentations and wailing were heard in the Queen’s apartments, and the twelve
days of mourning were held as if Ummeda had really deceased; on the expiration of
which the installation of his successor took place.”211

Ghosts Lengthening Themselves.

Ghosts, as we have already seen in the case of the Naugaza, have the power of changing
their length. In the well-known tale in the Arabian Nights the demon is shut up in a jar
under the seal of the Lord Solomon, as in one of the German tales the Devil is shut up in
a crevice in a pine tree, and the ghost of Major Weir of Edinburgh resided in his
walking-stick.212 Some of the Indian ghosts, like the Ifrît of the Arabian Nights, can
grow to the length of ten yojanas or eighty miles. In one of the Bengal tales a ghost is
identified because she can stretch out her hands several yards for a vessel.213 Some
ghosts possess the very dangerous power of entering human corpses, like the Vetâla, and
swelling to an enormous size. The Kharwârs of Mirzapur have a wild legend, which tells
how long ago an unmarried girl of the tribe died, and was being cremated. While the
relations were collecting wood for the pyre, a ghost entered the corpse, but the friends
managed to expel him. Since then great care is taken not to leave the bodies of women
unwatched. So, in the Panjâb, when a great person is cremated the bones and ashes are
carefully watched till the fourth day, to prevent a magician interfering with them. If he
has a chance, he can restore the deceased to life, and ever after retain him under his
influence. This is the origin of the custom in Great Britain of waking the dead, a practice
which “most probably originated from a silly superstition as to the danger of a corpse
being carried off by some of the agents of the invisible world, or exposed to the ominous
liberties of brute animals.”214 But in India it is considered the best course, if the corpse
cannot be immediately disposed of, to measure it carefully, and then no malignant Bhût
can occupy it. We have already met with instances of a similar idea of the mystic effect
supposed to follow on measuring or weighing grain.

Kindly Ghosts.

Most of the ghosts whom we have been as yet considering are malignant. There are,
however, others which are friendly. Such are the German Elves, the Robin Goodfellow,
Puck, Brownie and the Cauld Lad of Hilton of England, the Glashan of the Isle of Man,
the Phouka or Leprehaun of Ireland. Such, in one of his many forms, is the
Brahmadaitya, or ghost of a Brâhman who has died unmarried. In Bengal he is believed
to be more neat and less mischievous than other ghosts; the Bhûts carry him in a
palanquin, he wears wooden sandals, lives in a Banyan or Bel tree, and Sankhachûrnî is
his mistress. He appears to be about the only respectable bachelor ghost. In one of the
folk-tales a ghostly reaper of this class assists his human friend, and can cut as much of
the crop in a minute as an ordinary person can in a day.215 So, the Manx Brownie is
called the Fenodyree, and he is described as a hairy, clumsy fellow who would thresh a
whole barnful of corn in a single night for the people to whom he felt well disposed.216
This Brahmadaitya is the leader of the other ghosts in virtue of his respectable origin; he
lives in a tree, and, unlike other varieties of Bhûts, does not eat all kinds of food, but
only such as are considered ceremonially pure. He never, like common Bhûts, frightens
men, but is harmless and quiet, never plaguing benighted travellers, nor entering into the
bodies of living men or women, but if his dignity be insulted, or any one trespass on his
domains, he wrings their necks.

Tree Ghosts.

Hence in regard to trees great caution is required. A Hindu will never climb one of the
varieties of fig, the Ficus Cordifolia, except through dire necessity, and if a Brâhman is
forced to ascend the Bel tree or Aegle Marmelos for the purpose of obtaining the sacred
trefoil so largely used in Saiva worship, he only does so after offering prayers to the
gods in general, and to the Brahmadaitya in particular who may have taken up his abode
in this special tree.

These tree ghosts are, it is needless to say, very numerous. Hence most local shrines are
constructed under trees, and in one particular tree, the Bîra, the jungle tribes of Mirzapur
locate Bâgheswar, the tiger godling, one of their most dreaded deities. In the Konkan,
according to Mr. Campbell,217 the medium or Bhagat who becomes possessed is called
Jhâd, or “tree,” apparently because he is a favourite dwelling-place for spirits. In the
Dakkhin it is believed that the spirit of the pregnant woman or Churel lives in a tree, and
the Abors and Padams of East Bengal believe that spirits in trees kidnap children.218
Many of these tree spirits appear in the folk-tales. Thus, Devadatta worships a tree which
one day suddenly clave in two and a nymph appeared who introduced him inside the
tree, where was a heavenly palace of jewels, in which, reclining on a couch, appeared
Vidyatprabhâ, the maiden daughter of the king of the Yakshas; in another story the
mendicant hears inside a tree the Yaksha joking with his wife.219 So Daphne is turned
into a tree to avoid the pursuit of her lover.
The Brahmaparusha.

But there is another variety of Brâhman ghost who is much dreaded. This is the
Brahmaparusha or Brahma Râkshasa. In one of the folk-tales he appears black as soot,
with hair yellow as the lightning, looking like a thunder-cloud. He had made himself a
wreath of entrails; he wore a sacrificial cord of hair; he was gnawing the flesh of a man’s
head and drinking blood out of a skull. In another story these Brahma Râkshasas have
formidable tusks, flaming hair, and insatiable hunger. They wander about the forests
catching animals and eating them.220 Mr. Campbell tells a Marhâta legend of a master
who became a Brahmaparusha in order to teach grammar to a pupil. He haunted a house
at Benares, and the pupil went to take lessons from him. He promised to teach him the
whole science in a year on condition that he never left the house. One day the boy went
out and learned that the house was haunted, and that he was being taught by a ghost. The
boy returned and was ordered by the preceptor to take his bones to Gaya, and perform
the necessary ceremonies for the emancipation of his soul. This he did, and the uneasy
spirit of the learned man was laid.221 We have already encountered similar angry
Brâhman ghosts, such as Harshu Pânrê and Mahenî.

The Jâk and Jâknî.

The really friendly agricultural sprites are the pair known in some places as the Jâk and
Jâknî, and in others as Chordeva and Chordevî, the “thief godlings.” With the Jâk we
come on another of these curious survivals from the early mythology in a sadly degraded
form. As Varuna, the god of the firmament, has been reduced in these later days to
Barun, a petty weather godling, so the Jâk is the modern representative of the Yaksha,
who in better times was the attendant of Kuvera, the god of wealth, in which duty he was
assisted by the Guhyaka. The character of the Yaksha is not very certain. He was called
Punya-janas, “the good people,” but he sometimes appears as an imp of evil. In the folk-
tales, it must be admitted, the Yakshas have an equivocal reputation. In one story the
female, or Yakshinî, bewilders travellers at night, makes horns grow on their foreheads,
and finally devours them; in another the Yakshas have, like the Churel, feet turned the
wrong way and squinting eyes; in a third they separate the hero from the heroine because
he failed to make due offerings to them on his wedding day. On the other hand, in a
fourth tale the Yakshinî is described as possessed of heavenly beauty; she appears again
when a sacrifice is made in a cemetery to get her into the hero’s power, as a heavenly
maiden beautifully adorned, seated in a chariot of gold surrounded by lovely girls; and
lastly, a Brâhman meets some Buddhist ascetics, performs the Uposhana vow, and would
have become a god, had it not been that a wicked man compelled him by force to take
food in the evening, and so he was re-born as a Guhyaka.222

In the modern folk-lore of Kashmîr, the Yaksha has turned into the Yech or Yach, a
humorous, though powerful, sprite in the shape of a civet cat of a dark colour, with a
white cap on his head. This small high cap is one of the marks of the Irish fairies, and the
Incubones of Italy wear caps, “the symbols of their hidden, secret natures.” The feet of
the Yech are so small as to be almost invisible, and it squeaks in a feline way. It can
assume any shape, and if its white cap can be secured, it becomes the servant of the
possessor, and the white cap makes him invisible.223

In the Vishnu Purâna we read that Vishnu created the Yakshas as beings emaciate with
hunger, of hideous aspect, and with big beards, and that from their habit of crying for
food they were so named.224 By the Buddhists they were regarded as benignant spirits.
One of them acts as sort of chorus in the Meghadûta or “Cloud Messenger” of Kâlidâsa.
Yet we read of the Yaka Alawaka, who, according to the Buddhist legend, used to live in
a Banyan tree, and slay any one who approached it; while in Ceylon they are represented
as demons whom Buddha destroyed.225 In later Hinduism they are generally of fair
repute, and one of them was appointed by Indra to be the attendant of the Jaina Saint
Mahâvîra. It is curious that in Gujarât the term Yaksha is applied to Musalmâns, and in
Cutch to a much older race of northern conquerors.226

At any rate the modern Jâk and Jâknî, Chordeva and Chordevî, are eminently respectable
and kindly sprites. They are, in fact, an obvious survival of the pair of corn spirits which
inhabit the standing crop.227 The Jâk is compelled to live apart from the Jâknî in
neighbouring villages, but he is an uxorious husband, and robs his own village to supply
the wants of his consort. So, if you see a comparatively barren village, which is next to
one more productive, you may be sure that the Jâk lives in the former and the Jâknî in
the latter. The same is the character of the Chor or Chordeva and the Chornî or Chordevî
of the jungle tribes of Mirzapur.

Ghosts which Protect Cattle.


In the Hills there are various benevolent ghosts or godlings who protect cattle. Sâin, the
spirit of an old ascetic, helps the Bhotiyas to recover lost cattle, and Siddhua and
Buddhua, the ghosts of two harmless goatherds, are invoked when a goat falls ill.228 In
the same class is Nagardeo of Garhwâl, who is represented in nearly every village by a
three-pronged pike or Trisûla on a platform. When cows and buffaloes are first milked,
the milk is offered to him. It is perhaps possible that from some blameless godling of the
cow-pen, such as Nagardeo, the cultus of Pasupatinâtha, “the lord of animals,” an epithet
of Siva or Rudra, who has a stately shrine at Hardwâr, where his lingam is wreathed with
cobras, was derived. Another Hill godling of the same class is Chaumu or Baudhân, who
has a shrine in every village, which the people at the risk of offending him are supposed
to keep clean and holy. Lamps are lighted, sweetmeats and the fruits of the earth are
offered to him. When a calf dies the milk of the mother is considered unholy till the
twelfth day, when some is offered to the deity. He also recovers lost animals, if duly
propitiated, but if neglected, he brings disease on the herd.229

Another cattle godling in the Hills is Kaluva or Kalbisht, who lived on earth some two
hundred years ago. His enemies persuaded his brother-in-law to kill him. After his death
he became a benevolent spirit, and the only people he injured were the enemies who
compassed his death. His name is now a charm against wild beasts, and people who are
oppressed resort to his shrine for justice. Except in name he seems to have nothing to say
to Kâlu Kahâr, who was born of a Kahâr girl, who by magical charms compelled King
Solomon to marry her. His fetish is a stick covered with peacock’s feathers to which
offerings of food are made. He has more than a quarter of a million worshippers,
according to the last census, in the Meerut Division.

Bugaboos.

We close this long list of ghostly personages with those who are merely bugaboos to
frighten children. Such are Hawwa, probably a corruption through the Prâkrit of the
Sanskrit Bhûta, and Humma or Humu, who is said to be the ghost of the Emperor
Humayûn, who died by an untimely death. Akin perhaps to him are the Humanas of
Kumaun, who take the form of men, but cannot act as ordinary persons.230

These sprites are to the Bengâli matron what Old Scratch and Red Nose and Bloody
Bones are to English mothers,231 and when a Bengâli baby is particularly naughty its
mother threatens to send for Warren Hastings. Akin to these is Ghoghar, who represents
Ghuggu or the hooting of the owl.232 Nekî Bîbî, “the good lady;” Mâno or the cat;
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like