You are on page 1of 55
ssi Interpreted Languages: PHP, Pet, Python, Ruby (Sheet One)-Hyperpalygat Hyperpolyglot Interpreted Languages: PHP, Perl, Python, Ruby (Sheet One) a side-by-side reference shoot ‘sheet one: arithmetic and logic | stings | cenexes | dates and time | arays | dictionaries [functions | execution contra files | desctoios | processes and environment ‘shoot lwo Ubraries and modules | objects | nection | web [tests | debugging and profing| jaa interop | contact ‘php (3995) perl (3987) the vemonsused | 55 5.12; 5.14 29; 3.2 ‘molt one use stetets Anport 05, re, sys showsersion | ¢ php -version $ perl --version $ python -v smomrster | § php -F Foo.php $ pert fo0.p1 8 python £00.py ‘al $ php $ pert -ce 0 $ python '$ php =r “echo “hi\n"s* $ perl -e “print ("ni\n")" $ python -¢ "printy newline or 5 newlines not sepore statements mist be semicolon terminated Pot wate ter block dol 0 0 offside rute ‘assionment assignments can be asslanment | gy = 1; wea ‘don't return values wea List($, $7, $2) = array(l 42, D5 (8, $2) =) 2 3): my E=b a? paral #3 is discarded: ats discarded raises Valuetreor assignment | List(Sx, $y) «= array(a, 2, 3)3 (8x, $9) = (1, 2, 3)5 wy ed 23 #52 Set to MULL 4H Sz set to under: raises valueteror List(Sx, $y, $2) = array(t, 2)5 (Sx $y, $2) = (25 Ky toh2 swan LUst($x, $y) = array(Sy, $9) (Be 89) = (By. $05 Mynx ‘compound Jota tee 4 do not return val decrement | 7 = #86 one ss Fi faci me 1 in function body local seca | $7 MILLE vs none declare | $2 = rr: aes Th 0 ai yore List($y, $2) = array(2, 35 yee top Level top Level: ile recens wtich | “function or ne cssomn ution |" f thod body teste restabte (read only Serer | estate (with use clause): “net ton body fanesion or waste aronymous function body Snonymousfanceton body hyperpolyglotorgiseripting +185 ssi Interpreted Languages: PHP, Per, Python, Ruby (Sheet One) - Hyperpalygot anonymous block List(set, $22) = array(7, 8); ; our (als $82) = (2, 8): 2-78 samara | tion gra-eltels0 ¢ Sub Swap globats { Set Sap plobals(): ist($ahe i ler 5 (Set, $22) = ($22, $81); ‘global gl, g2 4 etal, Be) = arrose, sens ? fee eet onetant # uppercase identit declaration | detine(*P1", 3.24); vse constant PI => 3.14; # constant by conve Presta ‘wand-obine 47 conan # cormen commen! comment | {/ Conner’ i # conment gomment out | + coment Line Comment ine use ertpte quote st mulipelies | other Line °/ Srother Tine Seaman Line ul NULL # case insensitive wncet none culiest | f5_pulh($v) ne $v v= None PToset($0) | eetined $ AS None ‘undefined setae | ue ror under vse strict; otherwise undat | ratses nanteror Sane as null test; no distinction between | same os null test; no distinction between | not defined = False undefinedtest | defined variables and vartables set to | undefined vortables and variables set to. | try? v NULL net except NaneError: ¢ matic and logic 2 perk ' ftusand se | aye cause # case insensitve 1” True False fasenonds | aise wii @ @.@ * "9" array’) uneee @ @.8 ™" "0" False None @ 0.0 °° ‘eaical ait aa tlt operators | Lower precedence: Lower precedence: and or not andor so" and or nor not ‘ondiional exoression | $« > @? $x: -$« $0? $e: $x HAF x> @ else -x sompason | ete or eo > ¢>0 ce rumbers only: == I= > € >= comparison operator sparstas | ho conversion. Strings: eq ne gt It ge le Wee weeraue | pong een reno from Pythor ‘comparison "do" emp “re' ot Dy ‘one rom someon | 7 4 aya oe 7 + $ne22") stint | J's 4037 a9 6” 73.9 + Foat(’.037 sting svalue: “8 valve "value: ste(3) asthmatic Svoraiors | + - * / none X pon(b,e) tet Pome x stra integer divsion and | (int) (23 / 5) int (13/5) Bis smod one rove a, n= aivmed(3, § Hose (3) 7S foatdiision | 43/5 ass # Python 3: B/S ee Math sTrig am( antamatic | art exp tog sin cos tan asin acos atan | £2” asin acos ator); fron math saport se atone Jaget exp log sin cos tan asin acos atan | SH" 605» tans asir stan’ hyperpolyglotorgiseripting 2185 ssi Interpreted Languages: PHP, Per, Python, Ruby (Sheet One) - Hyperpolygot “don\'t say "n0"" mae | UDR, Say! st ‘truncation ceil ($x), int(round(x)) ita | Sls) sme Eon} aes re See, ay Bo floor ($x) weet aw(ain max); sn " mame | te wig a.9 soa sminandimax | $5°5 areay(2,2,3) mmax(22,3)3 Sinti231) nin($a) Ga = (1,2,3)5 veax([1,2,3]) me Ba Tg sas envi nw vss ceivister integer converted to float; use Math: becomes arbitrary ( uueciow converted to float ‘create arbitrary Length integers Jong foatovertow | yp inf raises OverflowErre ea saz ‘NaN error unless use Math: :Complex in effect a Eee, ae — vee nas EE rand(@,99) int(rand() * 160) mee, sre sommes Bs = cana random. gauss(®,1) srand(27); srand . random, seed(17) na($sd)5 random.setstate(sd) Deoperetors

You might also like