Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 30-10-2007, 07:10 PM   #1 (permalink)
TechFreakiez.com
 
Abhishek Dwivedi's Avatar
 
Join Date: Sep 2006
Location: New Delhi
Posts: 621
Arrow Perl Basics


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 :

http://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
__________________
Personal Log | Star date 05.04.2009: TDF Meet Kanpur was Awesome :D
www.TechFreakiez.com

Last edited by Abhishek Dwivedi; 01-11-2007 at 09:57 PM.
Abhishek Dwivedi is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 31-10-2007, 04:19 PM   #2 (permalink)
Broken In
 
ninad_mhatre85's Avatar
 
Join Date: Feb 2006
Posts: 116
Default Re: Perl Basics

Quote:
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";
__________________
Life is not measured by moments u breath but by the moments that take ur breath away
ninad_mhatre85 is offline  
Old 01-11-2007, 09:58 PM   #3 (permalink)
TechFreakiez.com
 
Abhishek Dwivedi's Avatar
 
Join Date: Sep 2006
Location: New Delhi
Posts: 621
Default Re: Perl Basics

edited....
__________________
Personal Log | Star date 05.04.2009: TDF Meet Kanpur was Awesome :D
www.TechFreakiez.com
Abhishek Dwivedi is offline  
Old 02-11-2007, 04:31 PM   #4 (permalink)
Right Off the Assembly Line
 
Join Date: Dec 2003
Location: Vadodara, Gujarat
Posts: 5
Default Re: Perl Basics

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 . i used it a lot for some cgi programmings in my job early .
__________________
Nobody is Perfect,
I am Nobody
Ankur is offline  
Old 03-11-2007, 12:03 AM   #5 (permalink)
Broken In
 
ninad_mhatre85's Avatar
 
Join Date: Feb 2006
Posts: 116
Default Re: Perl Basics

Quote:
Originally Posted by Abhishek Dwivedi
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 
  ?
__________________
Life is not measured by moments u breath but by the moments that take ur breath away
ninad_mhatre85 is offline  
Old 29-06-2008, 10:28 PM   #6 (permalink)
Broken In
 
r2d2's Avatar
 
Join Date: Oct 2006
Posts: 174
Default Re: Perl Basics

Quote:
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.
r2d2 is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
C Programming basics praka123 Programming 5 10-11-2007 01:59 PM
perl compiler vicky_l7 Programming 1 26-10-2007 10:20 AM
IRC basics Maverick340 QnA (read only) 27 17-08-2006 08:01 PM
Basics deadmanrulz Open Source 16 14-04-2005 05:21 PM

 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:44 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2