Mis on tõene? Tsüklid, failihaldus. if - näited. unless - näited. unless. Merle Sibola. if ($arv > $suur) { #leitakse suurim arv $suur=$arv; } #if

Similar documents
Puudub protseduur. Protseduuri nimi võib olla valesti kirjutatud. Protseduuri (või funktsiooni) poole pöördumisel on vähem argumente kui vaja.

Bioinformatics. Computational Methods II: Sequence Analysis with Perl. George Bell WIBR Biocomputing Group

Unix, Perl and BioPerl

Sequence Analysis with Perl. Unix, Perl and BioPerl. Why Perl? Objectives. A first Perl program. Perl Input/Output. II: Sequence Analysis with Perl

Tabelid <TABLE> Koostanud: Merike Hein

Control Structures. Important Semantic Difference

MSDE Upgrade platvormile SQL 2005 Server Express SP4

Perl for Biologists. Session 6 April 16, Files, directories and I/O operations. Jaroslaw Pillardy

COMS 3101 Programming Languages: Perl. Lecture 2

The Power of Perl. Perl. Perl. Change all gopher to World Wide Web in a single command

Outline. CS3157: Advanced Programming. Feedback from last class. Last plug

Appendix B WORKSHOP. SYS-ED/ Computer Education Techniques, Inc.

NAME DESCRIPTION. Declarations. Perl version documentation - perlsyn. perlsyn - Perl syntax

Regulaaravaldised Unixis ja Windowsis

Perl for Biologists. Regular Expressions. Session 7. Jon Zhang. April 23, Session 7: Regular Expressions CBSU Perl for Biologists 1.

What is PERL?

Script Programming Systems Skills in C and Unix

PERL Scripting - Course Contents

Andmebaasid (6EAP) I praktikum

Systems Skills in C and Unix

CS 230 Programming Languages

Perl Scripting. Students Will Learn. Course Description. Duration: 4 Days. Price: $2295

Vea haldus ja logiraamat hajutatud süsteemides Enn Õunapuu.

SQL Server 2005 Expressi paigaldamine

Introduction to Perl. Perl Background. Sept 24, 2007 Class Meeting 6

Perl for Biologists. Session 9 April 29, Subroutines and functions. Jaroslaw Pillardy

Scripting Languages Perl Basics. Course: Hebrew University

NAME DESCRIPTION. Declarations. Perl version documentation - perlsyn. perlsyn - Perl syntax

T-( )-MALV, Natural Language Processing The programming language Perl

Hands-On Perl Scripting and CGI Programming

Beginning Perl. Mark Senn. September 11, 2007

CSCI-GA Scripting Languages

ADDENDUM V: PERL SCRIPTS

print STDERR "This is a debugging message.\n";

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi

Indian Institute of Technology Kharagpur. PERL Part II. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T.

A control expression must evaluate to a value that can be interpreted as true or false.

Süsteemprogrammeerimine keeles C

A Crash Course in Perl5

COBOL Common Business-Oriented Language

They grow as needed, and may be made to shrink. Officially, a Perl array is a variable whose value is a list.

Indian Institute of Technology Kharagpur. PERL Part III. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T.

Perl. Many of these conflict with design principles of languages for teaching.

Perl. Perl. Perl. Which Perl

9.1 Origins and Uses of Perl

1. Introduction. 2. Scalar Data

EESTI STANDARD EVS-ISO 11620:2010

(Refer Slide Time: 01:12)

Introduction to Ruby. SWEN-250 Personal Software Engineering

EstEID Turvakiibi rakenduse kasutusjuhend

bash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017

COMS 3101 Programming Languages: Perl. Lecture 1

Perl for Biologists. Session 13 May 27, Parallelization with Perl. Jaroslaw Pillardy

Examples of Using the ARGV Array. Loop Control Operators. Next Operator. Last Operator. Perl has three loop control operators.

Optimization. Benchmark. simple use as timer. Biol Practical Biocomputing 1

Objektorienteeritud programmeerimine MTAT (6 EAP) 9. Loeng. H e l le H e i n h e l l e. h ee

8/13/ /printqp.php?heading=II BSc [ ], Semester III, Allied: COMPUTER PROGRAMMING-PERL -309C&qname=309C

1 Output and static... variables 2 Modifying variables Sophisticated... variables: arrays 4 Sophisticated...

File System User API

Perl for Biologists. Arrays and lists. Session 4 April 2, Jaroslaw Pillardy. Session 4: Arrays and lists Perl for Biologists 1.

# program uses modules nmap::parser and Data::Validate::IP use Nmap::Parser; use Data::Validate::IP qw(is_ipv4 is_ipv6);

Mälu interfeisid Arvutikomponendid Ergo Nõmmiste

# put all aligments together from one single original read

Programmeerimise 2. vaheeksam

CS4500/5500 Operating Systems File Systems and Implementations

Perl Primer An Introduction to Perl for C++ Programmers by Frank McCown and Tim Baird Harding University

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

This is a list of questions and answers about Unicode in Perl, intended to be read after perlunitut.

bash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017

Programming Perls* Objective: To introduce students to the perl language.

PERL MOCK TEST PERL MOCK TEST II

2017/11/20 20:24 1/2 Väljatrükkide häälestamine

Programming introduction part I:

Robot iehit amise j uhend Mikrokont rolleri programmeerimine C keeles Põhiline C keelest

Salvestusseadmed ja kettahaldus

IT441. Network Services Administration. Perl: File Handles

Learning Perl 6. brian d foy, Version 0.6, Nordic Perl Workshop 2007

class implementing objects of the correct type. Any additional arguments in the LIST are passed to

Processes and Shells

UNIX System Programming Lecture 3: BASH Programming

The svn-multi.pl Script

EECS402. PERL Basics

Ruby Topic Maps. Introduction to Ruby. Benjamin Bock.

The Unix Shell. Pipes and Filters

Provides ability to perform UNIX commands at some time in the future. At time time on day day, the commands in filefile will be executed.

ABIMATERJAL ROBOOTIKA TÖÖVIHIKULE Algoritmid ja programmeerimine

Kirje. Kirje. Tüpiseeritud fail. CASE-lause. Laiendatud klahvikoodid. 1

Java põhikursuse konspekt

More Scripting and Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

COMS 3101 Programming Languages: Perl. Lecture 6

Long-term Information Storage Must store large amounts of data Information stored must survive the termination of the process using it Multiple proces

LING/C SC/PSYC 438/538. Lecture 6 Sandiway Fong

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware

COMP284 Scripting Languages Lecture 3: Perl (Part 2) Handouts

2.3 Unix Streaming and Piping

Intermediate Perl. Boston University Information Services & Technology. Course Coordinator: Timothy Kohl

CMSC 330: Organization of Programming Languages. Ruby Regular Expressions

CSE 333 SECTION 3. POSIX I/O Functions

This file is copyright 2006 Mark Jason Dominus. Unauthorized distribution in any medium is absolutely forbidden. Domain Zone Checking.

file:///export/home/apostolo/work/tex/mkindex/mkgrki...

Transcription:

Mis on tõene? Tsüklid, failihaldus Merle Sibola iga string on tõene, välja arvatud "" ja "0" iga number on tõene, v.a. number 0 Iga viide (reference) on tõene Iga defineerimata muutuja on väär. if if (EXPR) { if (EXPR) { else { if (EXPR) { elsif (EXPR) { if (EXPR) { elsif (EXPR) { else { Tingimus sulgudes if - näited if ($arv > $suur) { #leitakse suurim arv $suur=$arv; #if if ($sone eq valmis ) { print Lõpetame.\n ; else { print Jätkame.\n ; unless unless (EXPR) { unless (EXPR) { else { unless (EXPR) { elsif (EXPR) { unless (EXPR) { elsif (EXPR) { else { unless ($a==1) { if ($a!= 1) { if (!($a == 1)) { unless - näited unless (chdir.. ) { print "Ei saa muuta kataloogi. Põhjus: $!\n\n"; #unless unless ($sone eq koik ) { uc $sone; 1

while / until LABEL while (EXPR) { LABEL while (EXPR) { continue { Kuni EXPR on tõene täidetakse tegevused. LABEL until (EXPR) { LABEL until (EXPR) { continue { Kuni EXPR on väär täidetakse tegevused while/until - näited while ($nimed[$i]) { print $nimed, ; $i++; until ($nimed[$i] eq ) { print $nimed[$i], ; $i++; Muutuja väärtuspiirkond while (my $rida = <STDIN>) { $rida = lc $rida; $i++ if $i == 0; Perli omapära continue { print $rida; #$rida on veel saadaval kiss ( me ) until $I_die; Shutup() unless $you_want_me_to_leave; #$rida pole enam väärtustatud for /foreach for (algväärtus; jätkamise tingimus; kuidas muutub väärtus) { for ($a=0; $a<26; $a++) { for ($a=0; $a<26; $a+=5) { foreach $väärtus @list { foreach $nimi ( Mart, Mati, Maret ) { print $nimi; for / foreach - näited for $count (10,9,8,7,6,5,4,3,2,1, PÕMM ) { print $count\n ; sleep(1); for (@christmas, @easter) { s/ham/turkey/; s/ham/turkey/ for @christmas, @easter; foreach $value (@array) {$sum+=$value foreach $key (sort keys %hash) { print $key => $hash{$key\n ; 2

Blokid while, until, for, foreach last LABEL; next LABEL; redo LABEL; RIDA: while ($line = <STDIN>) { chop ($line); last RIDA if ($rida eq lopp ); next RIDA if ($rida eq veel ); do - näited do{ $line = <STDIN>; until $line eq.\n ; do{{ next if $x == $y; until $x++ > $z; SWITCH for ($I = 0;$I < @ary1;$i++) { for ($j = 0;$j < @ary2;$j++) { WID: foreach $this (@ary1) { JET: foreach $that (@ary2) { SWITCH: { /^abc/ && do { $abc=1; last SWITCH; /^def/ && do { $nothing=1; või if (/^abc/ ) { elsif (/^def/) { else { $nothing=1; if ($ary1[$i] > $ary2[$j]) { last; $ary1[$i] += $ary2[$j]; next WID if $this > $that; $this += $that; Sisend ja väljund STDIN standard sisend (klaviatuur) $rida = <STDIN>; $rida = <FAIL>; STDOUT standard väljund (ekraan) print Tere ; print FAIL Tere ; Failist andmete lugemine open (FAIL, muu.txt ); $esimene_rida = <FAIL>; @ylejaanud_read = <FAIL>; while (<FAIL>) { print $_; close(fail); 3

Failist andmete lugemine (2) open (FAIL, andmed.txt ); while (<FAIL>) { chop; ($nimi,$synd,$lemmik) = split( ; ); if ($synd > 1990) { print Noored\n ; close (FAIL); Faili avamine open (FAIL,???miski.txt ); Lug K irj Lisa U us <PATH Y N N N >PATH N Y N Y >>PATH N Y Y Y +<PATH Y Y N N +>PATH Y Y N Y +>>PATH Y Y Y Y KÄSK N Y n/a n/a KÄSK Y N n/a n/a Lugemine ja kirjutamine unless (open LUG, <kust.txt ) { print Viga: $!\n ; unless (open KIRJ, >kuhu.txt ) { print Viga: $!\n ; while (<LUG>) { print KIRJ $_; close(lug); close(kirj); Printer /Meil open (PRINTER, lpr -Plp1 ) or die $!\n ; print PRINTER stuff\n ; close (PRINTER) or die $!\n ; unless (open (MAIL," /usr/lib/sendmail -t")) { print "Viga $!\n"; print MAIL "To: keegi\@ut.ee (Kellegi Nimi)\n"; print MAIL "From: minult\@ut.ee (Teine Nimi)\n"; print MAIL "Subject: Proov\n"; print MAIL See on juba meili sisu\n"; close(mail); Unixi käskude kasutamine open (SISU, ls -la. ); while (<SISU>) { print $_; close (SISU); Faili avamise viisid Perl 5.6 open (FH, < :raw, $path) or die $!\n ; :raw (binaarne) :text (tekst, vaikimisi) :latin1 (ISO - 8859-1) :utf8 (UTF - 8) :xml Programmifaili algusesse: use open IN => :any, OUT => :utf8 ; 4

Lehekülje kujundamise näide #!/usr/local/bin/perl format top= #lk pea defineerimine Nimi Kuu Summa --------------------------- format STDOUT= #lk defineerimine @<<<<<<< @ @##.## $nimi, $kuu, $summa Lehekülje kujundamise näide (2) unless (open(file,'nimed.txt')) { #faili avamine print Faili avamine ebaõnnestus. Põhjus: $! ; #unless while(<file>){ #faili väljastamine chop; ($nimi,$kuu,$summa)=split(';'); write; #while Lehekülje kujundamise näide (3) Faili sisu: merle;mai;4.98 riina;sept;31.8 Tulemus: Nimi Kuu Summa ---------------------------- merle mai 4.98 riina sept 31.80 #!/usr/local/bin/perl $kata='/home/merle_h/tekst/'; Kataloogi läbimine #kataloog unless ( opendir DIR, $kata) { #kat. avamine print "Viga. Kataloogi ei saa avada: $!\n"; $arv=0; #abimuutuja, mis loeb kataloogide arvu Kataloogi läbimine (2) while ($filename = readdir DIR) { # nimi ilma teeta next if substr($filename,0,1) eq. ; # peidetud faile ei näita print "$filename\n"; if (-d $filename) { $arv++; closedir DIR; print $arv,"\n"; #kataloogi korral suurendame #arvu ühe võrra #kataloogi sulgemine 5