Burning glass Technologies

Burning glass Technologies
Checktronix India Private Limited

Thursday, April 22, 2010

Perl Array

Today we can learn some thing about Array in perl.

An array variable starts with an @ symbol.

DEFINING AN ARRAY:

@num=(1,2,3,4);

@str=(‘hi’,’hello’,hey’);

COMBINING OF ARRAY:

Two array can be combined easily in perl

For Eg:

1.pl:

@num=(1,2,3,4);

@str=(‘hi’,’hello’,hey’);

@combine=(@num,@str);

Print “@combine\n”;

o/p: 1 2 3 4 hi hello hey

Simplify:

While declaring string in array we no need to waste time by giving quotes for that special quoting function is there qw.

Eg:

2.pl:

@color=qw(black green white);

CREATING A LIST USING RANGE OPERATOR:

@num=(1..20);

Will have no from 1 to 100

@letter=(‘a’..’z’);

One Example for swaping of numbers.

Its very easy in perl

3.pl

($a,$b)=(1,2);

print "before swap\n";

print "a=$a\n";

print "b=$b\n";

print "after swap";

($a,$b)=($b,$a);

print "after swap\n";

print "a=$a\n";

print "b=$b\n";

o/p:

before swap

a=1

b=2

after swap

a=2

b=1

TO FIND END OF ARRAY:

Just declare $#array name

4.pl

@num=(1..20);

print $#num;

o/p:

19.

Index starts from 0.

Monday, April 12, 2010

NEW GALAXY
A team of scientists from the UK and the US has discovered a galaxy far away from us which is churning out stars 250 times faster than our Milky Way. The discovery of the galaxy, about 10 billion light years away from the earth, will help researchers understand how the Milky Way was formed.

Galaxy SMM J2135- 0102 has four distinct star- forming regions, each of which is 100 times brighter than Milky Way locations such as the Orion Nebula. The team which discovered the galaxy was led by scientists from the UK's Durham University.

It also included researchers from European Southern University and the Massachusetts based Harvard- Smithsonian Center for Astrophysics." The new galaxy is forming stars at about 250 suns per year. Our Milky Way is forming about two suns per year," lead scientist Mark Swinbank of Durham University said. Because of the time it takes light to reach the earth, the scientists observed the galaxy as it would have appeared 10 billion years ago - just three billion years after the Big Bang.

PERL INTRO

INRODUCTION TO PERL:
Perl stands for Practical Extraction and Reporting Language. Perl is a general-purpose, high level, interpreted and dynamic computer programming language with a vast number of uses. Perl was invented by Larry Wall, a linguist working as a systems administrator at NASA in 1987. Today Perl is found in varied applications such as finance, manufacturing, genetics, the military etc to process large data sets. Perl is used to be one of the most popular languages for developing web applications. At that time, Perl is used to write CGI scripts. Perl is very good and optimized for problems that handle 90% of text and 10% of other. Perl is best for short and small programs that can be entered and run on a single command line.
Perl run well on UNIX and Windows systems. If you develop Perl for UNIX system, it can be portable to Windows system as well.
Download and install ActivePerl
You first need to download ActivePerl the latest version from http://www.activestate.com/activeperl/ . You can also find the installation files for other systems and versions via following link http://www.activestate.com/activeperl/downloads/
To install ActivePerl just double click on the installation file. It will guide you through steps with options. Just make your own choices and click next.
To check you installation you can open command line through Run windows and type following command: perl –version or perl -v. If you installed Perl successfully, you will see the version and copyright information.
FIRST PERL PROGRAM
First, you open the Open Notepad or Notepad++ and type the following code:
1. #E:/usr/bin/perl
2. print "Hello World!\n";
You can save the Perl source code file with any name and extensions you want. Perl source code file should has extension *.pl or *.ple (Perl executable).
Running the program:
Go to cmd prompt-> type perl filename.pl
Let's look at the program in more details.
The first line of the program is a special comment. Comments in Perl program start from the pound sign (#) to the rest of line. There is no sign for block comment.
The second line starts with print statement followed by a string “Hello World” and then followed by a semi-comma. Every Perl statement has to be ended with a semi-comma (;).