Custom Search

Monday, September 14, 2009

Initializing MySQL database



[root@localhost ~]# service mysqld status
mysqld is stopped

----------------------

[root@localhost ~]# service mysqld start
Initializing MySQL database:  Installing MySQL system tables...
090914 16:42:11 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
090914 16:42:11 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
OK
Filling help tables...
090914 16:42:11 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
090914 16:42:11 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
                                                           [  OK  ]
Starting MySQL:                                            [  OK  ]

----------------------

[root@localhost ~]# service mysqld status
mysqld (pid 4296) is running...

----------------------

[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.67 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> 

-----------------------

Saturday, September 12, 2009

How create Mysql User, Database and set privileges to user

How create Mysql User, Database and set privileges to user

[saju@localhost ~]$ mysql or mysql -u root  or mysql -u root -p

mysql> create user 'saju'@'localhost' identified by '123456';

mysql> create database if not exists `sajudb`;

mysql> grant all on sajudb.* to saju@localhost identified by "123456" with grant option;

[saju@localhost ~]$ mysql sajudb -u saju -p

mysql> show databases

mysql> use sajudb


Linux Partition Naming Convention IDE SCSI

Linux Partition Naming Convention IDE SCSI

IDE Hard Disk
*************
hda --> hd0 --> First Hard Disk (connected in IDE1)
hdb --> hd1 --> Second Hard Disk (connected in IDE2)

hda0 --> Not exist
hda1 --> (hd0,0) --> First partition in First Hard Disk
hda2 --> (hd0,1) --> Second partition in First Hard Disk
hda3 --> (hd0,2) --> Thired partition in First Hard Disk

hdb0 --> Not exist
hdb1 --> (hd1,0) --> First partition in Second Hard Disk
hdb2 --> (hd2,1) --> Second partition in Second Hard Disk
hdb3 --> (hd1,2) --> Thired partition in Second Hard Disk

---------------

20GB  -- hda1 --> (hd0,0) --> First partition in First Hard Disk(First Primary Partition)
20GB  -- hda2 --> (hd0,1) --> Second partition in First Hard Disk(Second Primary Partition)
20GB  -- hda3 --> (hd0,2) --> Thired partition in First Hard Disk(Thired Primary Partition)
100GB -- hda4 --> (hd0,3) --> Extended Partition.
  |
  --> 25GB  -- hda5 --> (hd0,4) --> First Logical Partition in Extended Partition
      25GB  -- hda6 --> (hd0,5) --> Second Logical Partition in Extended Partition
      25GB  -- hda7 --> (hd0,6) --> Thired Logical Partition in Extended Partition
      25GB  -- hda8 --> (hd0,7) --> Fourth Logical Partition in Extended Partition

---------------
* only can create 4 primary partitions in a system.To create more partitions, create an extended partiotion and then create any number of logical partitions in it.

* In linux we can set boot flag in Logical and Primary partitions to boot OS from that partiotion.But Windows set boot flag only in Primary Partition. 

*  Grub (boot loader) know only IDE naming convention Eg: hda1,hda2. Grub dont understand SCSI naming convention Eg: sda1,sda2.

---------------

SCSI Hard disk
**************

sda  --> First Hard Disk
sdb  --> Second Hard Disk

sda0 --> Not exist
sda1 --> First partition in First Hard Disk
sda2 --> Second partition in First Hard Disk
sda3 --> Thired partition in First Hard Disk

sdb0 --> Not exist
sdb1 --> First partition in Second Hard Disk
sdb2 --> Second partition in Second Hard Disk
sdb3 --> Thired partition in Second Hard Disk


20GB  -- sda1 --> First partition in First Hard Disk(First Primary Partition)
20GB  -- sda2 --> Second partition in First Hard Disk(Second Primary Partition)
20GB  -- sda3 --> Thired partition in First Hard Disk(Thired Primary Partition)
100GB -- sda4 --> Extended Partition.
  |
  --> 25GB  -- sda5 --> First Logical Partition in Extended Partition
      25GB  -- sda6 --> Second Logical Partition in Extended Partition
      25GB  -- sda7 --> Thired Logical Partition in Extended Partition
      25GB  -- sda8 --> Fourth Logical Partition in Extended Partition

*****************************************

Howto Restore Linux After Windows Installation

Howto Restore Linux After Windows Installation

1)Make directory.step1 and step2 are not necessary if you boot from linux cd in 'rescue' mode.
mkdir /mnt/sysimage

2) Mount root (/) partiton.Suppose our root partition is 'sda5'.
mount /dev/sda5 /mnt/sysimage
or
Boot from linux cd in 'rescue' mode. Then mount root (/) partition to '/mnt/sysimage'.

3)In rescue mode changing root to mounted partition.This is for accessing binaries(grub-install,grub) in the '/bin' and '/sbin' directories in the root (/) partition (mounted partition).

sh-3.2#  chroot /mnt/sysimage

sh-3.2#  ls
sh-3.2#  vim /boot/grub/grub.conf
sh-3.2#  vim /boot/grub/menu.lst

4) Installing grub to hard disk.

sh-3.2#  greb-install /dev/sda

sda --> First hard disk (represent a whole hard disk)
If it finished with message 'Installation finished, no error reported' go to next step.

5) To go to grub shell.
sh-3.2#  grub 

6)
grub> root (hd0,4)

* remember to use space between 'root' command and (hd0,4).
* Here we specifing the partition where '/boot' directory exist. If linux completly installed in a single partition (Eg:sda5) then use 'root (hd0,4)'. if we installed root (/) in 'sda5' and created a seperated partition 'sda8' for '/boot', then you have to specify the partition where '/boot' present, that is use 'root (hd0,7) here.

(hd0,4) --> sda5
(hd0,7) --> sda7

7)
grub> setup (hd0)

you will you get a success message.

8) Exit from grub shell
grub> quit

9) Checking 'grub.conf'.

sh-3.2#  vim /boot/grub/grub.conf

A)
* 'grub.conf' file of system with root (/) and '/boot' installed in seperated partition. Here root (/) installed in 'sda5 or (hd0,4)' and '/boot' installed in 'sda7 or (hda0,8).
----------
default=0
timeout=5
splashimage=(hd0,7)/grub/splash.xpm.gz    # --- Equal to sda7/grub/splash.xpm.gz means /boot/grub/splash.xpm.gz
hiddenmenu
title Fedora 10 (2.6.27.5-117.fc10.i686)
        root (hd0,7)  # --- Partition where '/boot' exist for search 'Kernal' and 'initrd' images. 
        kernel /vmlinuz-2.6.27.5-117.fc10.i686 ro root=UUID=c5b6e260-4732-45e9-b9a5-9f9b27991049 rhgb quiet
        initrd /initrd-2.6.27.5-117.fc10.i686.img
title Windows XP
        rootnoverify (hd0,0)
        chainloader +1
-----------
 * Here 'root=UUID=c5b6e260-4732-45e9-b9a5-9f9b27991049' (UUID of partition /dev/sda5)  or 'root=/dev/sda5'.Partition where root (/) file system exist.
 * Type 'vim /etc/fstab' to see 'UUID' of partitions. 

B)
* If linux completly installed in a single partition (Eg:sda5) then 'grub.conf' become look like
----------
default=0
timeout=5
splashimage=(hd0,5)/grub/splash.xpm.gz    # --- Equal to sda5/grub/splash.xpm.gz means /boot/grub/splash.xpm.gz
hiddenmenu
title Fedora 10 (2.6.27.5-117.fc10.i686)
        root (hd0,5)  # --- Partition where '/boot' exist for search 'Kernal' and 'initrd' images. 
        kernel /vmlinuz-2.6.27.5-117.fc10.i686 ro root=/dev/sda5 rhgb quiet
        initrd /initrd-2.6.27.5-117.fc10.i686.img
title Windows XP
        rootnoverify (hd0,0)
        chainloader +1
-----------
* 'root=/dev/sda5' Partition where root (/) file system exist.


10) Checking 'menu.lst'.

sh-3.2#  vim /boot/grub/menu.lst
do step9

11) reboot your system If above steps are ok.Thanks

*********************************************************

Create Sample Linux Kernel Module and insert it.

Tested in Debian Lenny
1) # apt-get install linux-headers

Select 'linux-headers-2.6.26-2-686' and install it ,based on kernel version of your system.
Use # uname -r to get kernel version.

# apt-get install linux-headers-2.6.26-2-686


2) Create hello.c kernel module file: vim hello.c

#include
< linux/module.h >
#include
< linux/kernel.h >

int init_module(void)
{
printk(KERN_INFO "init_module() called\n"); ----> this is printed in /var/log/messages when inserting or initializing kernel module hello.ko
return 0;
}

void cleanup_module(void)
{
printk(KERN_INFO "cleanup_module() called\n"); ----> this is printed in /var/log/messageswhen cleaning or removing kernel module hello.ko
}

3) Create a Makefile: vim Makefile
All you need to do is (edit) change Makefile to use current kernel build directory'/lib/modules/2.6.26-2-686/build/'.

obj-m += hello.o

all:
make -C /lib/modules/2.6.26-2-686/build M=$(PWD) modules

clean:
make -C /lib/modules/2.6.26-2-686/build M=$(PWD) clean

Here $PWD return current working directory(where hello.c amd Make file are saved).Here files in the current working directory are compiled at current kernel directory '/lib/modules/2.6.26-2-686/build/' ,then clean it.

4) To build kernel module enter:
$ make

5) Run ls command to see newly build kernel module:
$ ls
hello.c hello.mod.c hello.o modules.order
hello.ko hello.mod.o Makefile Module.symvers

6) Here hello.ko is kernel module file. To see information about module, enter:
$ modinfo hello.ko 

7) To load kernel module, enter:
$ insmod hello.ko
or
$ modprobe hello

8) To list installed Linux kernel module, enter:
$ lsmod
$ lsmod | grep hello

9) To remove hello Linux kernel module, enter:
$ rmmod hello

10) This module just logs message to a log file called /var/log/messages (/var/log/syslog), enter:
$ tail -f /var/log/messages

Python PyQt basic

PyQt Basic

#pyuic4 student.ui ----> For create python code from 'student.ui' file.

#pyuic4 student.ui > stud.py -----> For create python code from 'student.ui' file and save into file 'stud.py'.

#vim stud.py ---> Open 'stud.py' file and edit and add some lines.

#python stud.py ----> for run python file 'stud.py'

------------ BEFORE EDIT stud.py -------------

# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'student.ui'
#
# Created: Sat Jul 25 19:00:30 2009
# by: PyQt4 UI code generator 4.4.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui

class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(519, 230)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtGui.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(40, 40, 51, 31))
self.label.setObjectName("label")
self.lineEdit = QtGui.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(100, 40, 141, 31))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(100, 70, 141, 31))
self.lineEdit_2.setObjectName("lineEdit_2")
self.lineEdit_3 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_3.setGeometry(QtCore.QRect(100, 100, 141, 31))
self.lineEdit_3.setObjectName("lineEdit_3")
self.label_2 = QtGui.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(40, 80, 51, 18))
self.label_2.setObjectName("label_2")
self.label_3 = QtGui.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(40, 110, 61, 21))
self.label_3.setObjectName("label_3")
self.submit_b = QtGui.QPushButton(self.centralwidget)
self.submit_b.setGeometry(QtCore.QRect(40, 150, 71, 27))
self.submit_b.setObjectName("submit_b")
self.clear_b = QtGui.QPushButton(self.centralwidget)
self.clear_b.setGeometry(QtCore.QRect(110, 150, 51, 27))
self.clear_b.setObjectName("clear_b")
self.cancel_3 = QtGui.QPushButton(self.centralwidget)
self.cancel_3.setGeometry(QtCore.QRect(160, 150, 61, 27))
self.cancel_3.setObjectName("cancel_3")
self.textBrowser = QtGui.QTextBrowser(self.centralwidget)
self.textBrowser.setGeometry(QtCore.QRect(250, 0, 261, 141))
self.textBrowser.setObjectName("textBrowser")
self.pushButton_4 = QtGui.QPushButton(self.centralwidget)
self.pushButton_4.setGeometry(QtCore.QRect(250, 150, 81, 27))
self.pushButton_4.setObjectName("pushButton_4")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionHfgh = QtGui.QAction(MainWindow)
self.actionHfgh.setObjectName("actionHfgh")
self.actionJfgj = QtGui.QAction(MainWindow)
self.actionJfgj.setObjectName("actionJfgj")
self.actionJgfj = QtGui.QAction(MainWindow)
self.actionJgfj.setObjectName("actionJgfj")

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("MainWindow", "Name:", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("MainWindow", "Mark:", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("MainWindow", "Course:", None, QtGui.QApplication.UnicodeUTF8))
self.submit_b.setText(QtGui.QApplication.translate("MainWindow", "submit", None, QtGui.QApplication.UnicodeUTF8))
self.clear_b.setText(QtGui.QApplication.translate("MainWindow", "clear", None, QtGui.QApplication.UnicodeUTF8))
self.cancel_3.setText(QtGui.QApplication.translate("MainWindow", "cancel", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_4.setText(QtGui.QApplication.translate("MainWindow", "Display", None, QtGui.QApplication.UnicodeUTF8))
self.actionHfgh.setText(QtGui.QApplication.translate("MainWindow", "hfgh", None, QtGui.QApplication.UnicodeUTF8))
self.actionJfgj.setText(QtGui.QApplication.translate("MainWindow", "jfgj", None, QtGui.QApplication.UnicodeUTF8))
self.actionJgfj.setText(QtGui.QApplication.translate("MainWindow", "jgfj", None, QtGui.QApplication.UnicodeUTF8))

-------- AFTER EDIT stud.py -----------

# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'student.ui'
#
# Created: Fri Jul 24 12:28:57 2009
# by: PyQt4 UI code generator 4.4.3
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

class Ui_MainWindow(QtGui.QMainWindow):#creating our class by inheriting 'QtGui.QMainWindow'. ----> 1

def __init__(self): # constructor. ---->2
self.widget=QtGui.QMainWindow() #Creating object of class 'QtGui.QMainWindow' for window or screen. ----> 3
self.setupUi(self.widget) #calling method 'setupUi' by passing object of winodw or screen. ----> 4

def setupUi(self, MainWindow):#method for setup user interface by placing each widgets on window or Screen.
MainWindow.setObjectName("MainWindow")#'MainWindow' is the object we created in the constructor.
MainWindow.resize(519, 230)
self.centralwidget = QtGui.QWidget(MainWindow)#'self'means object of this class 'Ui_MainWindow'.
self.centralwidget.setObjectName("centralwidget")
self.label = QtGui.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(40, 40, 51, 31))
self.label.setObjectName("label")
self.lineEdit = QtGui.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(100, 40, 141, 31))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(100, 70, 141, 31))
self.lineEdit_2.setObjectName("lineEdit_2")
self.lineEdit_3 = QtGui.QLineEdit(self.centralwidget)
self.lineEdit_3.setGeometry(QtCore.QRect(100, 100, 141, 31))
self.lineEdit_3.setObjectName("lineEdit_3")
self.label_2 = QtGui.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(40, 80, 51, 18))
self.label_2.setObjectName("label_2")
self.label_3 = QtGui.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(40, 110, 61, 21))
self.label_3.setObjectName("label_3")
self.pushButton = QtGui.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(40, 150, 71, 27))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(110, 150, 51, 27))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtGui.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(160, 150, 61, 27))
self.pushButton_3.setObjectName("pushButton_3")
self.textBrowser = QtGui.QTextBrowser(self.centralwidget)
self.textBrowser.setGeometry(QtCore.QRect(250, 0, 261, 141))
self.textBrowser.setObjectName("textBrowser")
self.pushButton_4 = QtGui.QPushButton(self.centralwidget)
self.pushButton_4.setGeometry(QtCore.QRect(250, 150, 81, 27))
self.pushButton_4.setObjectName("pushButton_4")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionHfgh = QtGui.QAction(MainWindow)
self.actionHfgh.setObjectName("actionHfgh")
self.actionJfgj = QtGui.QAction(MainWindow)
self.actionJfgj.setObjectName("actionJfgj")
self.actionJgfj = QtGui.QAction(MainWindow)
self.actionJgfj.setObjectName("actionJgfj")

QtCore.QObject.connect(self.pushButton,QtCore.SIGNAL("clicked()"),self.fun)# 'self.fun' -->pointer to signal handling function 'fun',. ----> 11

def fun(self): ----> 12
print "hello"

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)#all code for connect must before this line.

def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("MainWindow", "Name:", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("MainWindow", "Mark:", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("MainWindow", "Course:", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("MainWindow", "submit", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_2.setText(QtGui.QApplication.translate("MainWindow", "clear", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_3.setText(QtGui.QApplication.translate("MainWindow", "cancel", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_4.setText(QtGui.QApplication.translate("MainWindow", "Display", None, QtGui.QApplication.UnicodeUTF8))
self.actionHfgh.setText(QtGui.QApplication.translate("MainWindow", "hfgh", None, QtGui.QApplication.UnicodeUTF8))
self.actionJfgj.setText(QtGui.QApplication.translate("MainWindow", "jfgj", None, QtGui.QApplication.UnicodeUTF8))
self.actionJgfj.setText(QtGui.QApplication.translate("MainWindow", "jgfj", None, QtGui.QApplication.UnicodeUTF8))

import sys #for import OS(Operating Systems) system functions. ----> 5

if __name__ == "__main__": ----> 6
app=QtGui.QApplication(sys.argv) # in 'argv' by default contain our program name. ----> 7
obj=Ui_MainWindow() #creating object 'obj' of our application class 'Ui_MainWindow'. ----> 8
obj.widget.show() # to show all widgets in the our application object 'obj'. ----> 9
sys.exit(app.exec_()) ----> 10

----------------------------------------------

Python and MySQL database

Python and MySQL database connection

Save file as student.py then in terminal type
#python student.py ----> to run python file 'student.py'
-------------------------
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtSql import *

# DB type, host, user, password...
db = QSqlDatabase.addDatabase("QMYSQL"); #'QMYSQL' is the driver name
db.setHostName("periyar")
db.setDatabaseName("saju1db")
db.setUserName("root")
db.setPassword("123456")
ok = db.open()

# True if connected
if ok:
print "Connected to MySQL"
else:
print "ERROR connecting to MySQL"

query = QSqlQuery(db)
if query.exec_("SHOW TABLES"): # it return true or false.
while query.next():
table = query.value(0).toString() # Here 'value' attribute is a tuple.
print table

query1 = QSqlQuery(db)
if query1.exec_("select * from student"):
while query1.next():
i=0
while i<3: i="i+1">

how to download whole website using wget

man wget

wget -r -l2 -P/home/saju/ http://mysite.com/

How to make keyboard leds dancing using linux unix shell script

save this code in file keyled.sh, then
Press Ctrl +Alt + F2 or F1 -----> to goto Terminal.
chmod 777 keyled.sh -----> to make keyled.sh executable
then run the script by typing ./keyled.sh i terminal.
Press Ctrl +Alt + F7 ----->to go back to GNOME

man setled
man sleep
-----------------------------------------------------------------------------------
while true
do
setleds +num
sleep .5
setleds -num
sleep .5
setleds +caps
sleep .5
setleds -caps
sleep .5
setleds +scroll
sleep .5
setleds -scroll
done
---------------------------------------------------------------------------------------

Perl Basic 1


**************************************************************

my $str = "Hello saju how are you"  # Declaring and initializing a variable '$str'.

## Finding ##
$str =~ /pattern/          # Equivalent to function 'regmatch(pattern,$str)'.
Example:  $str =~ /saju/   # Finding for pattern 'saju' in variable '$str'.

## Finding and substituting or replacing ##
$str =~ s/pattern/replacement/  # Equivalent to function 'regsubstitute(pattern,replacement,$str)'.
Example: $str =~ s/saju/sanu/   # Finding for pattern 'saju' in variable '$str' and replace it with 'sanu'.

**************************************************************

# Regular expression is written in between / ... /.
# A few 11 characters mean something special in between / ... / , they are
  [], {}, (), *, +, ?, ., \, ^, $, | 
# Other characters in between / ... / just means themselves.

# \ ---> Backslash removing special meaning of special characters in between / ... / s

**************************************************************

### Character Classes ###

[aeiou] ---> Match any one of these characters a,e,i,o,u.
Example: /p[aeiou]t/  matches pat,pet,pit,pot,put.
Example: /p[^aeiou]t/ it not maches pat,pet,pit,pot,put.But it maches pbt,pct,pdt,----.

## character class shortcuts ##

[0123456789] ----> \d
[abc..xyxABC...XYZ0123456789_] ----> \w  # Except white space.
[ \n\r\t\f] ----> \s   # White space charater class.

[^0123456789] ----> \D
[^abc..xyxABC...XYZ0123456789_] ----> \W 
[^ \n\r\t\f] ----> \S   # opposite of White space charater class.

. ---> 'dot' shortcut matches any character(whilte space character,abc---xyzADC---XYZ0123456789_).It is widely used.

## character class shortcuts Examples ##

 /\d\d-\d\d-\d\d\d\d/  ---> 12-11-2009
 /\d\d\/\d\d\/\d\d\d\d/ ---> 11/10/2009
#or
 m{\d\d/\d\d/\d\d\d\d}  ---> 11/10/2009 # This method is used to avoid usage of delimiter Backslash '\' .Here we using m{..} sinstead of /../.

**************************************************************
### Quantifiers ###

# Normally, we match exactly one (thing)literal character or character class.
# Put a quantifier after a (thing) literal character or character class to change that.
# We can say we want to match
 1) Zero or one (thing) literal character or character class.  ---> ?
 2) Zero or more (thing) literal character or character class. ---> *
 3) One or more (thing) literal character or character class.  ---> +

## Zero or One thing --> ?   ##

/sa?ju/ ----> Matches 'saju', 'sju'. Here literal character 'a' matches Zero or One time. Not matches 'saaju'.

/s[aj]?u/ ----> Matches 'sju', 'sau', 'su'. Not matches 'saju'.Here characters in the character class '[aj]' matches Zero or One time,


## Zero or More thing --> *  ##

/sa*ju/ ----> Matches 'saju', 'sju', 'saaaju', etc. Here literal character 'a' matches Zero or More times.

/s[aj]*u/ ----> Matches 'saaaju', 'sjjju', 'saaajjju', 'su', 'saju', 'sajajaajju'.Here characters in the character class '[aj]' matches Zero or More times.


## One or More thing --> +   ##

/sa+ju/ ----> Matches 'saju', 'saaaju'. Not matches 'sju'. Here literal character 'a' must matches One or More times.

/s[aj]+u/ ----> Matches 'saju', 'saaaju', 'sajjju', 'saaajjju', sajajaajju'. Not matches 'su'.Here characters in the character class '[aj]' must matches One or More times.


## Without Qualifiers ##

/(s[aj]u)/ ----> Matches 'sau', 'sju'. Not matches 'saju','su'.


**************************************************************
### Anchors ###

\A  ---> Matches only at te begining of the text.It must be first thing in Regular Expression.

\Z  ---> MAtches only at the end, or newline followed by end. It must be last thing in Regular Expression.

Examples:

/\A\d+/ ---> Line start with digits.

/\s\d{5}\Z/ ----> Line end with space and 5 digits.


**************************************************************

### Capturing Groups ###

# Parentheses '()' capture whatever they match in $1,$2,----.
# Count left-most parentheses to get corresponding $n.

Example:

/\A(\w+),\s+([A-Z][A-Z])\s+(\d{5})\Z/  then,

print "City: $1 , State: $2 , Zip: $3 ";

**************************************************************
**************************************************************

###  $_   ###

$_   ---> It is default variable for pattern matching and pattern substitution or replacement.

**************************************************************
### <> ###

Diamond operator or readline operator.

**************************************************************

chomp $str;   ---> function 'chomp' remove last character from a string if it is a newline '\n' character.

**************************************************************