This tutorial was made on Os x. But the process should be similar if not identical on any UNIX based operating system. Just substitute the cmd button for the ctrl button.
Start by opening a new terminal window
Applications>Utilities>terminal.app
Then change your directory to the desktop
cd Desktop
Now create a new file using the nano command in the terminal. Nano is a terminal based text editor.
nano filename.plx
Your terminal window should now look similar to this
When starting a new perl document always start with the following.
#!/usr/bin/perl
This lets the terminal know which runtime environment to use. Now, let's start by making a hellrld application. Type the following code into the terminal.
print "Hello World! \n";
The print command is what tells the environment to display text.
Notice the quotation marks. You can use either single or double quotation marks. Double quotation marks allow you to use code such as \n within the quotation. If you use single quotation marks any code within the quotation marks will not be seen as code. It will be seen as plain text.
Notice how at the end I put /n. /n is a command that tells the environment to create a new line. If we did not include this than a new line would not be printed and the bash prompt will appear directly after the printed text.
Now that we have our code written and understand what each part of the code is doing we need to save it. This can be done by pressing "^o" or ctrl and "o" at the same time and pressing the enter button. This will save the file to the desktop or what ever directory you are in.
Now you'll want to open up a new terminal tab. This can be done by going to the shell menu and clicking new tab or holding cmd and "t" at the same time.
Change your directory to the desktop again.
cd Desktop
Now you'll want to chmod the file so that it is an executable.
chmod +x file.plx
chmod stands for "Change mode". And the "+x" changes the file to an executable.
Now you'll want to open the file. This can be done via the following command.
perl file.plx
or
./file.plx
You can use either of those commands to open the file. The perl command will open the file even if you didn't chmod it to an executable. However, the ./ command will only work if the file is an executable.
If you did everything correct you should get this.
If you have any questions feel free to ask .
Results 1 to 6 of 6
Thread: [perl] Lesson #1 (Hello world)
- 30 Dec. 2010 12:27am #1
[perl] Lesson #1 (Hello world)
// Signature
- 20 Jan. 2011 11:27am #2
- Join Date
- Nov. 2009
- Location
- -.- in front of the computer...
- Posts
- 514
- Reputation
- 26
- LCash
- 11.10
Thomas, i would like to know what is that application, because at our school we are using microsoft visual c++
- 20 Jan. 2011 11:31am #3
- 16 Jun. 2011 02:45am #4
More precisely, it's something that you won't use in Windows. Terminals are more commonly used in Linux, Unix, and anything based off of those systems (Apple's stuff, for example). Windows has the Command Line, but honestly, it's almost never used (by regular users) because creating graphical applications is simple and effective (and usually regular Windows users lack the knowledge to properly use terminals).
In Windows you need to download a Perl binary to be able to run the scripts, I believe.
@Thomas: Good to see someone putting up Perl tutorials around here! I know this is an old thread, but I deemed this question worthy of a more elaborate answer. Perl is mighty powerful for string manipulation. Definitely something your tutorials should lead to, especially regular expressions. Good job! I'll be reading your tutorials and giving feedback!
- 16 Jun. 2011 02:56am #5
- 16 Jun. 2011 09:37pm #6