Cov txheej txheem:

Kawm Perl Yooj Yim rau Nruab Nrab: 8 Kauj Ruam
Kawm Perl Yooj Yim rau Nruab Nrab: 8 Kauj Ruam

Video: Kawm Perl Yooj Yim rau Nruab Nrab: 8 Kauj Ruam

Video: Kawm Perl Yooj Yim rau Nruab Nrab: 8 Kauj Ruam
Video: Искусственный интеллект! Генерация изображений с помощью DALL·E 2 2024, Kaum ib hlis
Anonim
Kawm Perl Yooj Yim rau Nruab Nrab
Kawm Perl Yooj Yim rau Nruab Nrab

Perl yog cov ntawv nyeem raws li kev sau ntawv languge uas muaj nws qhov zoo thiab qhov tsis zoo, qhov kev qhia no yuav muab koj cov ntsiab lus ntawm cov hauv paus thiab kev ua haujlwm uas feem ntau cov kws sau ntawv (AKA; programers)

yuav siv. QHOV TSEEM CEEB! (rau lub qhov rais ua haujlwm nkaus xwb) Kuv tab tom kwv yees tias koj tau ua haujlwm nrog lub ntiaj teb nyob zoo program ua ntej lossis/thiab ua haujlwm nrog tus cuam tshuam. thaum sau ntawv hauv perl koj yuav tsum hloov koj PATH, tab sis yog tias koj tsis xav ua qhov no, siv perl nthuav qhia (qhia hauv qab no). *ceeb toom plese tus nqi thiab tawm tswv yim qhia no

Kauj Ruam 1: Cov Khoom Siv

1.a perl interpeter (google nws!)

2.if koj xav tau, perl nthuav qhia (google nws!) 3.yog li, yog tias koj xav tau, modules (google perl modules rau qee qhov) nruab cov modules hauv "lib" nplaub tshev hauv koj phau ntawv teev npe perl interpeter

Kauj Ruam 2: Koj Thawj Txoj Haujlwm

ok cia ua qhov program yooj yim, theej thiab muab qhov #!/usr/bin/perl sau "nyob zoo ntiaj teb"; qhov ntawd yog txoj haujlwm yooj yim tshaj plaws uas koj tuaj yeem ua, yog tias koj xav ntxiv rau nws me ntsis, ntaus #!/usr/bin/perl print "nyob zoo / n ntiaj teb"; koj tau ua koj thawj qhov haujlwm!, / n yog los ua kab tshiab tam sim no cia kom tau txais qib me ntsis ntxiv

Kauj ruam 3: Variables

tam sim no muaj peb hom kev hloov pauv, 1.scalers (tuav ib kab ntawm cov ntaub ntawv) (($ scaler lub npe = tus nqi;) 2.arrays (tuav ntau daim kab xev ntawm cov ntaub ntawv) ((@array name = (values);) 3. hashes %hashname = (tus nqi => lwm tus nqi, tus nqi => lwm tus nqi #suav nrog ntau ntawm cov theses raws li koj xav tau)

Kauj Ruam 4: Tau Txais Ntau Ntxiv

cia ua cov ntawv sau uas luam tawm qhov tseem ceeb ntawm kev hloov pauv, ntaus cov ntawv no! (koj tsis tas yuav sau cov lus pom, cov lus pom tau sau nrog #) 1. #!/usr/bin/perl $ variablename = 5; sau "$ variablename"; 2. #!/usr/bin/perl @arrayname = (tus nqi, tus nqi 2); #nco ntsoov, koj yuav tsum xa mus rau arrays raws li piv txwv piv txwv (qhov ntsuas tau nyob rau hauv kev txiav txim pib ntawm xoom luam tawm "$ arrayname {0} n"; #print tus nqi sau "$ arrayname {1} n"; #print value2 note: rau cov cai saum toj no {thiab} cov cim yog qhov ua piv txwv kab zauv 3. #!/usr/bin/perl kuv %hash = (v => tus nqi, v2 => tus nqi 2); luam tawm $ hash {v}; tam sim no cia kawm paub lwm qhov siv rau scalers, ntaus lossis luam thiab muab cov lej no #!/usr/bin/perl $ scalername =; luam tawm $ scalername; ntaus txhua yam koj xav tau thaum siv qhov hais kom ua sai tab sis yog tias koj siv perl nthuav qhia, nyem rau std.input ces nyem rau ntawm i/o cim cim cia cia pom qee qhov kev siv ntau ntxiv rau cov lej

Kauj Ruam 5: Lwm Qhov Siv thiab Looping

theej thiab muab cov cai no #!/usr/bin/perl $ scalername =; yog ($ scalername = ~ m/bill clinton/) {print "nws clinton zoo lawm!"; } ua li cas, koj yuav nug "ua li cas yog tias ua?" nqes mus thiab koj yuav pom! >>>>>>>> hauv qhov yog tias kev cai lij choj perl coj tus cwj pwm zoo li hauv qab no, perl nug "puas yog $ scalername muaj daim nqi clinton? "ntawm no yog lwm txoj haujlwm uas tseem siv tau ntau yam thaum ua piv txwv: luam thiab muab cov cai no #!/usr/bin/perl $ a = 1; thaum ($ a == 1) # == yog rau cov lej nkaus xwb {print "a = 1"; } lwm {print "a tsis sib npaug 1"; } cov kauj ruam tom ntej yuav tham txog kev ua haujlwm boolean

Kauj ruam 6: Boolean

boolean yog rau cov lej nkaus xwb! heres qee qhov haujlwm ==, sib npaug! =, tsis sib npaug <, ntau dua>, tsawg dua (*), suav ntau ntxiv: hauv kev sib npaug tsis muaj () 's +, ntxiv

Kauj Ruam 7: Muab Nws Ua Ke

theej thiab muab tus lej no, #!/usr/bin/perl $ ua haujlwm =; yog ($ ua haujlwm = ~ m/sib npaug/) {luam tawm "sau tus lej: / n"; $ a =; luam "sau tus lej rau sib npaug $ a: / n "; $ b =; $ c = $ a * $ b; luam tawm" $ a sib npaug los ntawm $ b = $ c / n ";} yog ($ ua haujlwm = ~ m/ntxiv/) {luam tawm "sau tus lej: / n"; $ a =; luam "sau tus lej ntxiv rau $ a: / n"; $ b =; $ c = $ a + $ b; luam "$ ntxiv rau $ b = $ c / n ";}

Kauj ruam 8: Ua tiav

thaum koj sau koj tus kheej cov haujlwm koj yuav xav ntxiv qhov haujlwm no hauv koj cov cai

siv ceeb toom; ok koj ua tau!

Pom zoo: