PERL Class Lesson 2
FIRST SCRIPT
lesson2 overview
next script, Hello World
FIRST SCRIPT
- In SSH terminal type: vim first.pl and hit Enter
- Once in vim, create the following script
The first line #!/usr/bin/env perl is called the "SHEBANG"
It tells the computer what language you are about to start talking in and where it can find the so called dictionary to understand what you are going to tell it to do.
Then next line starts with a pound sign # and anything following that is a comment which means it is there for the programmer and basically does nothing but remind or explain whatever you want to put there.
The use strict tells the computer that it must follow strict rules, nothing just slides on by.
The use warnings tells the computer that it must tell us if there is an error in our coding.
Every line must end in a semi-colon ; that tells the computer that we are done with that line of code and it needs to move on to the next line of code and read that one as a seperate command.
The print command tells the computer to display or print the following words or numbers out onto the screen when the program is run.
- Now save the script (wq first.pl )
- Then in the SSH Shell we change the permissions so it will work for us (chmod 755 first.pl)
- And now we run it to test if everything is coded correctly ( ./first.pl )
- to run anything in perl you have to put a dot . and a slash / in front of it and then hit ENTER
When Trying To Run first.pl Notice How An Error Is Displayed
Can't locate warning.pm in @INC (@INC contains:
/usr/lib/perl5/5.8.8/x86_64-linux
/usr/lib/perl5/5.8.8
/usr/lib/perl5/site_perl/5.8.8/x86_64-linux
/usr/lib/perl5/site_perl/5.8.8
/usr/lib/perl5/site_perl/5.8.5
/usr/lib/perl5/site_perl/5.8.4
/usr/lib/perl5/site_perl/5.8.3
/usr/lib/perl5/site_perl/5.6.2
/usr/lib/perl5/site_perl .) at ./first.pl line 4.
BEGIN failed--compilation aborted at ./first.pl line 4.
- Warning.pm can't be found because it is suppose to be use warnings with an s at the end
- Fix the script making sure you have use warnings with an s on the end of it
- Run it again and this time you should see 'words' butted right up in front of your location or pwd
Congratulations!!!! You just got the computer to output something.
=======================================
lesson2 overview
next script, Hello World