90 likes | 115 Views
Learn the fundamentals of Perl programming with this introductory guide. Understand variables, strings, and numbers in Perl, and start coding simple scripts. No prior experience required!
E N D
Programming in PerlIntroduction Peter Verhás January 2002.
Hello Word print ”Hello World!”; It is that simple just like BASIC!
Perl is an interpreted language • Program is text file • Perl loads it, compiles into internal form • Executes the intermediate code
Hello World # 2 $a = 123; $b = 55; $c = $a + $b; $d = "kakukk\n"; $d = 'kakukk\n' if $c == 178; if( $d eq "kakukk\n" ){ print "Hello World!\n"; }else{ print "This is not a good day!\n"; } OUTPUT: This is not a good day!
Variables $a = 123; $b = 55; $c = $a + $b; $d = "kakukk\n"; $d = 'kakukk\n' if $c == 178; if( $d eq "kakukk\n" ){ print "Hello World!\n"; }else{ print "This is not a good day!\n"; } • Variables start with $ • There is nothing like reserved words • $else $if $while are good variables
Strings $a = 123; $b = 55; $c = $a + $b; $d = "kakukk\n"; $d = 'kakukk\n' if $c == 178; if( $d eq "kakukk\n" ){ print "Hello World!\n"; }else{ print "This is not a good day!\n"; } • ”kakukk\n” is interpolated string • ’kakukk\n’ is NOT interpolated, 8 characters
Numbers $n = 1234; # decimal integer $n = 0b1110011; # binary integer $n = 01234; # octal integer $n = 0x1234; # hexadecimal integer $n = 12.34e-56; # exponential notation $n = "-12.34e56"; # number specified as a string $n = "1234"; # number specified as a string
This program is a liar $a = 123; $b = 55; $c = $a + $b; $d = "kakukk\n"; $d = 'kakukk\n' if $c == 178; if( $d eq "kakukk\n" ){ print "Hello World!\n"; }else{ print "This is not a good day!\n"; } • It prints This is not a good day! • which is actually not true, is it?