Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Basics Web Programming.

Similar presentations


Presentation on theme: "Programming Basics Web Programming."— Presentation transcript:

1 Programming Basics Web Programming

2 Programming Intro What is programming? Why do we need it?
breaking down tasks into small steps e. g. count the words in “program=set of instructions to perform a task.” Why do we need it? Computer is not “intelligent”. Computer can perform multiple tasks fast and reliably. How do we do it? Learn to think logically and detail-oriented. Learn the syntax of a specific programming language. Practice (code, execute, debug, repeat). Design & implement systems. Web Programming

3 Perl Intro: What is Perl?
What is Perl? (Practical Extraction and Report Language) an interpreted programming language optimized for string manipulation, I/O, and system tasks Interpreted (vs. compiled) programming language code & execute (vs. code-compile-execute) translated to machine code at runtime (vs. compile time) faster to program/debug/modify slower execution time since “intepreted” at runtime simpler (easier to learn, but less powerful) Web Programming

4 Perl Intro: Why Perl? Why Perl? relatively easy to learn
well-suited for CGI tasks CGI tasks (translation btw. user and server) involve string manipulation. Advantages (speed, power) of compiled languages are negligible in CGI environment. CGI tasks usually do not require heavy computations. Network bandwidth is the bottleneck in the Web. portable: runs on most (Web server) O/S WIRED article: “Perl Simplifies the Labyrinth That is Programming Language” Web Programming

5 Perl Basics Basic Syntax
free form spaces, indentations have no meaning to Perl interpreter. program statements end in ; comments start with #, end at the line break. Running a Perl program (from unix command line) method 1 perl [-switch] program_name method 2 put #!/usr/bin/perl at the first line in the script. set file permission to be executable. Chmod 755 program_name program_name Web Programming

6 Example #1 # my first program print “I program, therefore I am.”;
‘print’ sends to standard (screen) output. Web Programming

7 Example #2 #!/usr/bin/perl # using a variable $name= “Sam”;
print “I am $name. Who are you?\n”; $ denotes a (scalar) variable. “$name” resolves the variable. ‘\n’ is a newline character. Web Programming

8 Example #3 #!/usr/bin/perl # interacting w/ user $my_name= “Sam”;
print “I am $my_name. Who are you?”; $your_name= <STDIN>; print “$your_name, it’s nice to meet you.”; <STDIN> reads from standard (keyboard) input. Web Programming

9 Example #4 #!/usr/bin/perl # paying attention to user interface
$my_name= “Sam”; print “\nI am $my_name. Who are you?\n ”; $your_name= <STDIN>; chomp $your_name; print “$your_name, it’s nice to meet you.\n\n”; ‘chomp’ deletes the newline character. Web Programming

10 Example #5 #!/usr/bin/perl # working with numbers $a=1; $b= 2+2; $c= 2*2; $d= $b/$c; print “$a = $d”; print “\n”; Web Programming


Download ppt "Programming Basics Web Programming."

Similar presentations


Ads by Google