Status
Not open for further replies.

Abhishek Dwivedi

TechFreakiez.com
Hi guys

Am kinda new to this section of programming…actually the whole section is new…lol…and this is my first post here, so please pardon any kind of mistake or stupidity…


Perl

This is a bit old language and not used a lot these days but it really helps a lot in the development of security related programs and learning Programming logics and much more...

I’ll keep on updating this post whenever I get time as am just a student of class 11 who is buzzzyyyy in his studies…lol…


Basics :

Perl was developed by Larry Wall in 1987 by fusing Unix Utility with a System Administration Tool that he had developed.
Perl is an interpreted language i.e. its code is run as it is and not compilied like in C++ and other languages.
Before beginning you need to download the Perl Interpreter for windows 32 bit system from here :

*www.activestate.com/


“My First Perl Program”:

In order to write a perl program you do not need any kind of New or Strange Editor…simple editors like notepad will do the work best. (this is the best feature of perl.lol.) Now Open Notepad and type the following :

print ‘This is my first perl program\n’;

Now save this file by the name “Name.pl” (remember to keep the extension as .pl always). Now Open Dos Prompt and type this :

C:\perl>Name.pl (assuming that you save the file in C:\perl\ directory)

When you press Enter,

This is my first perl program

will be printed on the screen….

Now lets analyse this little program…the “PRINT” calls the output function that displays everything from within the quotes on the screen. The “\n” means new line or carriage return. “;” signifies the the statement ends here.

Now lets learn how to use scalars in our program.

Scalars are declared by the $ sign followed by the Variable name which can be anything (without space…you can use‘_’).

Open Notepad and type the following:

$scalarvariable= ‘My First Perl Program\n’;
print “$scalarvariable”;

When you run this program, you will get an output as follows:

My First Perl Program

The 1st line of the program stores the text “My First Perl Program” inside a scalar named scalarvariable and the 2nd line prints the value of scalarvariable on the screen.

Note: Perl performs Variable interpolation within double quotes i.e. it replaces the variable name with the value if the variable.
Lets take one more example:

Open Notepad and type the following:

$scalarvariable= ‘My First Perl Program\n’;
print ‘$scalarvariable’;

The output of this program will be as follows:

$scalarvariable

With the above example example you can easily understand the function of “” and ‘’ in perl.




Interacting with the user is the most important part of the program. In Perl, you can take input from the user using < > operators or the Diamond Operators. This is very similar to the cin function defined in iostream.h of the C++ header file. This operator simply takes the input from the user and waits for the user to press the Enter key and hence it can never be used to halt the screen at any point like the function getch() does…

Open Notepad and type the following:

print ‘Enter your name=’;
$name=<>;
print “\nIs your name $name ?”;

The output of this program will be:
Enter your name= Abhishek
Is your name Abhishek ?

The 1st like prints “Enter your name=” (without quotes) and the 2nd line will ask for the input to store $name. The 3rd line prints “Is your name” value of $name “?”(without quotes) i.e. it will print the value of $name on the screen preceded by “Is your name” (without quotes).


I will be updating this thread daily (frm 4th of nov.) but I would like to know your response on this thread. SO guys please comment…

thanks
 
Last edited:

ninad_mhatre85

Journeyman
Print ‘Enter your name=’;
$name=<>;
print “\nIs your name $name ?”;

u should chomp the input taken otherwise output would be
Code:
C:\Documents and Settings\idc193577\Desktop>perl temp.pl
Enter your name=abcd

Is your name abcd
 ?

as well as in first print statement P is in caps so it wont work code should be
Code:
print "Enter your name =" ;
chomp ($name=<STDIN>) ;
print "\nIs your name $name ?\n";
 

Ankur

Right off the assembly line
perl is a superb language dude ... any documentation can be found/downloaded from perldoc.perl.org.

perl modules (pms) can be found on www.CPAN.org ... a too useful site ....

The perldoc.perl.org docs are also installed on windows with activestate perl and are same as on the site.

Perl is great in regex matching :p. i used it a lot for some cgi programmings in my job early :).
 

ninad_mhatre85

Journeyman
Abhishek Dwivedi said:
Code:
  The output of this program will be:
  Enter your name= Abhishek
  Is your name Abhishek ?

output wont be like that i already posted in my previous post that when u read from STDIN it also read newline character ("\n") and u should remove that to do that chomp the variable in which u read user input. output of ur script would be that "?" will go on next line.
Code:
  The output of this program will be:
  Enter your name= Abhishek
  Is your name Abhishek 
  ?
 

r2d2

Journeyman
Abhishek Dwivedi
Perl is an interpreted language i.e. its code is run as it is and not compilied like in C++ and other languages.
Before beginning you need to download the Perl Interpreter for windows 32 bit system from here :

This is not entirely true cos perl internally compile the script to bytecode and execute it, but this process is completely transperent to the user.
 
Status
Not open for further replies.
Top Bottom