Skip to content

Commit

Permalink
Spell check and typos
Browse files Browse the repository at this point in the history
  • Loading branch information
dhimavanth committed Apr 6, 2020
1 parent f442375 commit 87c4eed
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 91 deletions.
4 changes: 2 additions & 2 deletions perl/data-types/data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Perl is a loosely typed language and hence you no need to define the type of the
Perl has three basic data types:

1. Scalars
2. arrays
3. hashes
2. Arrays
3. Hashes

## 1. Scalars

Expand Down
2 changes: 1 addition & 1 deletion perl/hashes/hashes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Hash is an unordered set of key/value pairs. They are preceded by `%`.

Array elements are accessed by using it's indices. But Hashes are accesed using it's descriptive keys.
Array elements are accessed by using it's indices. But Hashes are accessed using it's descriptive keys.

## Example

Expand Down
22 changes: 11 additions & 11 deletions perl/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@
}
]
},
{
"title" : "Arrays",
"path" : "arrays",
"links" : [
{
"title" : "Arrays",
"path" : "arrays"
}
]
},
{
"title" : "Strings",
"path" : "strings",
Expand Down Expand Up @@ -69,6 +59,16 @@
}
]
},
{
"title" : "Arrays",
"path" : "arrays",
"links" : [
{
"title" : "Arrays",
"path" : "arrays"
}
]
},
{
"title" : "Hashes",
"path" : "hashes",
Expand Down Expand Up @@ -105,7 +105,7 @@
},
{
"title" : "OOPS in Perl",
"path" : "oops",
"path" : "oops-in-perl",
"links" : [
{
"title" : "OOP Principles",
Expand Down
48 changes: 24 additions & 24 deletions perl/introduction/introduction.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Perl(Practical Extraction and Report Language) is especially desined for text processing by Larry Wall. Perl is a high level programming language and hence one can easily undertand Perl as the programs are in simple english.
Perl(Practical Extraction and Report Language) is especially designed for text processing by Larry Wall. Perl is a high level programming language and hence one can easily undertand Perl as the programs are in simple english.

## Key features
* Cross-platform programming language
Expand Down Expand Up @@ -35,41 +35,41 @@ print "Hello World!!"; // to display "Hello World!!"
3. Follow the installation steps to finish the setup.
4. Once the installation is completed, check the installation by using the below command in command prompt.

```sh
perl -v
```
```sh
perl -v
```

## 2. On Linux
1. Most Linux modern Linux distributions come with a recent version of Perl. If not, you can download the software form [Perl Downloads](https://www.perl.org/get.html)
2. Execute the below commands
```sh
tar -xzf perl-5.30.2.tar.gz
cd perl-5.30.2
$./Configure -de
$make
$make test
$make install
```
```sh
tar -xzf perl-5.30.2.tar.gz
cd perl-5.30.2
$./Configure -de
$make
$make test
$make install
```

### Note :
Change the version based on the file you have downloaded in the above commands

## 3. On MacOS

1. Recent MacOS come with a recent version of Perl. If not, you can download the software form [Perl Downloads](https://www.perl.org/get.html)
1. Recent MacOS will have Perl installed in-built. If not, you can download the software form [Perl Downloads](https://www.perl.org/get.html)
2. change the directory
```sh
cd ~/Downloads
```
```sh
cd ~/Downloads
```
3. Run the below commands
```sh
tar -xzf perl-5.30.2.tar.gz
cd perl-5.30.2
./Configure -de
make
make test
make install
```
```sh
tar -xzf perl-5.30.2.tar.gz
cd perl-5.30.2
./Configure -de
make
make test
make install
```

### Note :
Change the version based on the file you have downloaded in the above commands
Expand Down
2 changes: 1 addition & 1 deletion perl/lists/lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ print("happy", 16) # prints happy16
```
### Check result [here](https://onecompiler.com/perl/3vnqnmnss)

Lists are indexed like arrays and indices starts from zero, means list[0] refers to first element and to access nth element, you should list[n-1].
Lists are indexed like arrays and indices starts from zero, means `list[0]` refers to first element and to access nth element, you should use `list[n-1]`.

```perl
print((1,2,3,4,5)[0]); # to access first element
Expand Down
2 changes: 1 addition & 1 deletion perl/oops-in-perl/oops.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ Encapsulation is a mechanism to protect private hidden data from other users. It

Polymorphism gives the meaning many forms, usually it occurs when multiple classes are present and have been inherited.

Consider an example of installing an application in your mobile, where your base class is `Mobile` and method is `installation()` and its derived classes could be installApp1, installApp2, installApp3 etc which will have its own implementation but installation method can be common which can be inherited from its base class.
Consider an example of installing an application in your mobile, where your base class is `News` and method is `subscribeNews()` and its derived classes could be Sports, Politics, Business, Weather etc which will have its own implementation but the method `subscribeNews()` can be common which can be inherited from its base class.
5 changes: 3 additions & 2 deletions perl/sub-routine/sub-routine.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Sub-routine is a function which contains set of statements. Usually they are written when multiple calls are required to same set of statements which increases re-usuability and modularity.

Sub-routine allows you to divide your large lines of code into smaller ones. Usually the division happens logically such that each function performs a specific task and is up to developer. You can define a sub-routine anywhere in you program. You can also use sub-routines defined in some other programs. `use`, `do` or `require` statements are used to load sub-routines defined in other programs.
Sub-routine allows you to divide your large lines of code into smaller ones. Usually the division happens logically such that each function performs a specific task and is up to developer. You can define a sub-routine anywhere in your program. You can also use sub-routines defined in some other programs. `use`, `do` or `require` statements are used to load sub-routines defined in other programs.

`eval()` function is used to generate a sub-routine at run-time. `sub` is the keyword used to define a sub-routine
* `eval()` function is used to generate a sub-routine at run-time.
* `sub` is the keyword used to define a sub-routine

## How to define a sub-routine

Expand Down
2 changes: 1 addition & 1 deletion perl/variables/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ print "I love $fruits"
```
### Check result [here](https://onecompiler.com/perl/3vnmn3yty)

You might expect the output as `I love mango` but you might be surprised to see the output as `I love`. This is because `fruit` and `fruits` are two different variables and `fruits` is not assigned with any value. To avoid these king of mistakes while programming, Perl provides a pragma called strict which requires you to declare variable explicitly before using the variable is used. `my` is used to declare variables when you use `strict`.
You might expect the output as `I love mango` but you might be surprised to see the output as `I love` without throwing any error. This is because `fruit` and `fruits` are two different variables and `fruits` is not assigned with any value. To avoid these king of mistakes while programming, Perl provides a pragma called `strict` which requires you to declare variable explicitly before using the variable is used. `my` is used to declare variables when you use `strict`.

The above example when you use `strict`

Expand Down
96 changes: 48 additions & 48 deletions perl/working-with-databases/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ In this chapter, let's learn how to interact with MySQL database in Perl.

There are multiple ways to install MySQL drivers, one of the ways is by using `CPAN`.

```sh
perl -MCPAN -e shell
```
```sh
perl -MCPAN -e shell
```
* To install `DBD::mysql` use the below command,

```sh
install DBD:mysql
```
```sh
install DBD:mysql
```
* Installation progress can be seen in command prompt.

## How to connect to MySQL database server

Consider we are creating a sample database called `test`

```sh
my $dbh = DBI->connect("DBI:mysql:test",'root','');
```
```sh
my $dbh = DBI->connect("DBI:mysql:test",'root','');
```

DBI->connect has three parameters:
1. Data source name
Expand All @@ -36,52 +36,52 @@ DBI->connect returns false when the connection is not established.
## Insert data in to the database

Once the connection is established, you can insert data into the tables. Consider you are inserting data into DATA_TABLE
```perl
my $sth = $dbh->prepare("INSERT INTO DATA_TABLE
(NAME, ID, OCCUPATION )
values
('foo', 123, 'doctor')");
$sth->execute() or die $DBI::errstr;
print "Inserted rows:" + $sth->rows;
$sth->finish();
$dbh->commit or die $DBI::errstr;
```
```perl
my $sth = $dbh->prepare("INSERT INTO DATA_TABLE
(NAME, ID, OCCUPATION )
values
('foo', 123, 'doctor')");
$sth->execute() or die $DBI::errstr;
print "Inserted rows:" + $sth->rows;
$sth->finish();
$dbh->commit or die $DBI::errstr;
```

## Read data from tables

```perl
my $sth = $dbh->prepare("SELECT NAME, ID
FROM DATA_TABLE
WHERE OCCUPATION = 'doctor'");
$sth->execute() or die $DBI::errstr;
print "Number of records whose occupation is doctor :" + $sth->rows;
while (my @row = $sth->fetchrow_array()) {
my ($name, $id ) = @row;
print "Name = $name, ID = $id\n";
}
$sth->finish();
```
```perl
my $sth = $dbh->prepare("SELECT NAME, ID
FROM DATA_TABLE
WHERE OCCUPATION = 'doctor'");
$sth->execute() or die $DBI::errstr;
print "Number of records whose occupation is doctor :" + $sth->rows;
while (my @row = $sth->fetchrow_array()) {
my ($name, $id ) = @row;
print "Name = $name, ID = $id\n";
}
$sth->finish();
```

## Updating a record

```perl
my $sth = $dbh->prepare("UPDATE DATA_TABLE
SET OCCUPATION = 'student'
WHERE ID = 123");
$sth->execute() or die $DBI::errstr;
print "Updated rows:" + $sth->rows;
$sth->finish();
$dbh->commit or die $DBI::errstr;
```
```perl
my $sth = $dbh->prepare("UPDATE DATA_TABLE
SET OCCUPATION = 'student'
WHERE ID = 123");
$sth->execute() or die $DBI::errstr;
print "Updated rows:" + $sth->rows;
$sth->finish();
$dbh->commit or die $DBI::errstr;
```

## Deleting a record

```perl
my $sth = $dbh->prepare("DELETE FROM DATA_TABLE
WHERE ID = 123");
$sth->execute( $id ) or die $DBI::errstr;
print "Deleted rows:" + $sth->rows;
$sth->finish();
$dbh->commit or die $DBI::errstr;
```
```perl
my $sth = $dbh->prepare("DELETE FROM DATA_TABLE
WHERE ID = 123");
$sth->execute( $id ) or die $DBI::errstr;
print "Deleted rows:" + $sth->rows;
$sth->finish();
$dbh->commit or die $DBI::errstr;
```

0 comments on commit 87c4eed

Please sign in to comment.