COMP519: Web Programming Autumn 2007 Perl Tutorial: The very beginning A basic Perl Program The first line Comments and statements Simple printing Running.

Slides:



Advertisements
Similar presentations
زبان برنامه نویسی پرولوگ
Advertisements

معاونت درمان امور مامایی اردیبهشت 90. برای ثبت اطلاعات در برنامه نرم افزاری نظام مراقبت مرگ پریناتال ابتدا لازم است برنامه نرم افزار info-path وپرنیان.
مراحل مختلف اجرای يک برنامه
فایل پردازی در C File based Programming in C. انواع فایل متنی –سرعت بالا –حجم کمتر –امکان دسترسی تصادفی –حفظ امنیت داده ها دودویی (باینری) –امکان باز.
PHP Hypertext per processor کار می کند؟ PHP چگونه
1 Other Java Related Technologies. 2 HTML DOM 3 HTML DOM مجموعه ای استاندارد از اشیاء را برای HTML تعریف می کند و یک راه استاندارد برای دسترسی و دستکاری.
COMP519: Web Programming Autumn 2007 Perl Tutorial: Beyond the Basics Keyboard Input and file handling Control structures Conditionals String Matching.
1 Network Address Translation (NAT). 2 Private Network شبکه خصوصی شبکه ای است که بطور مستقیم به اینترنت متصل نیست در یک شبکه خصوصی آدرس های IP به دلخواه.
1 بنام خدا زبان برنامه نویسی C (21814( Lecture 14 Structures.
COMP519: Web Programming Autumn 2010 Perl Tutorial: The very beginning  A basic Perl Program The first line Comments and statements Simple printing 
Database Laboratory: Session #4 Akram Shokri. DB-Lab 2 Lab Activity You must already created all tables You have to have inserted proper data in tables.
به نام خدا برنامه سازی سمت سرور (php)
1 بنام خدا زبان برنامه نویسی C (21814( Lecture 9 Selected Topics.
In the next lectures you will learn  What is SQL  How to access mySQL database  How to create a basic mySQL database  How to use some basic queries.
1 بنام خدا زبان برنامه نویسی C (21814( Lecture 8 Chapters 8 & 9.
موضوع: دبير مربوطه: آموزشگاه : اجرا : عبارتهای جبری خانم مقصودی
تمام اسب ها همرنگ هستند! Basis: h = 1 We have only one horse. Clearly all horses in the set are the same color. Inductive hypothesis: In any set of up.
مظفر بگ محمدی دانشگاه ایلام Generics. کدهای عمومی 2 یکی از اهداف OOP ایجاد قابلیت نوشتن برنامه های عمومی با قابلیت استفاده ی مجدد است. کدهای چندریخت تا.
Data Types Modifiers Base data type Size Sign signed int 2 B unsigned float 4 B short double 8 B long char 1 B.
Arrangements of Lines C omputational Geometry By Samaneh shafi naderi
CS Constraint Satisfaction Constraint Satisfaction Problems Chapter 5 Section 1 – 3 Modified by Vali Derhami.
آشنايي با سيستم اعداد.
به نام خدا.
[c.
تهیه و تنظیم: فاطمه قاسمی دانشگاه صنعتی شریف – پاییز 86
تهیه و تنظیم: فاطمه قاسمی دانشگاه صنعتی شریف – پاییز 86
تمرین هفتم بسم الله الرحمن الرحیم درس یادگیری ماشین محمدعلی کیوان راد
بنام خدا زبان برنامه نویسی C (21814( Lecture 2 Chapter 3
ویژگی های DHCP جلوگیری از Conflict سرعت بخشیدن به کارها مدیریت متمرکز
جلسه اول 12/7/1388 مدرس: دکتر خالدیان
دانشکده مهندسی کامپیوتر
بنام خدا زبان برنامه نویسی C (21814( Lecture 12 Selected Topics
SY800 router mode [AD-14-TB ].
ساختمان داده ها جداول درهم سازی
ساختمان داده‌ها الگوریتمهای کوتاهترین مسیر
آزمایشگاه پایگاه داده ها قیود در جداول یک پایگاه داده در SQL Server
چگونه بفهمیم آیا ژورنالی ISI است؟ ایمپکت فاکتور دارد یا خیر؟
آموزش مقدمات MATLAB سیگنال ها و سیستم ها دانشگاه صنعتی شریف پائیز 86
بنام خدا زبان برنامه نویسی C (21814( Lecture 10 Chapter 11
فصل دوم جبر بول.
Route configuration for 5400W ADSL Router
SSO Single Sign-on Systems
آشنایی با پایگاه داده mysql
آموزش کرک کردن نرم افزار ACTIVE HDL
Tree Sort.
مدارهای منطقی فصل سوم - خصوصیات توابع سويیچی
ساختمان داده‌ها پیمایش درخت دودویی
آشنایی مقدماتی با نرم افزار Endnote X4
تهیه و تنظیم: فاطمه قاسمی دانشگاه صنعتی شریف – پاییز 86
ASP.NET فرناز شریعت.
آشنایی با نرم افزار لینگو
تهیه و تنظیم: فاطمه قاسمی دانشگاه صنعتی شریف – پاییز 86
Bucket sort اكرم منوچهري زهرا منوچهري
راهنمای استفاده از ابزار Mailings در Ms Word
پشته و صف پیوندی Give qualifications of instructors: DAP
بسم الله الرحمن الرحیم هرس درخت تصمیم Dr.vahidipour Zahra bayat
کاربرد کامپیوتر در داروخانه
جستجوی منابع الکترونیک
فصل ششم مدارهای ترتیبی.
JavaScript مظفر بگ محمدی.
ساختمان داده‌ها درختان و درختان دودویی
دکتر مظفر بگ محمدی دانشگاه ایلام
سخت افزارهای امنیتی Hardware Security تهیه و ارایه : یونس جوان.
Uniprocessor Scheduling
kbkjlj/m/lkiubljj'pl;
ساختمان داده ها مرتب سازی درجی
پشته و صف پیوندی Give qualifications of instructors: DAP
مباني كامپيوتر و برنامه سازي Basics of Computer and Programming
مباني كامپيوتر و برنامه سازي Basics of Computer and Programming
آشنایی با فرایند داده کاوی در نرم افزار R گروه داده کاوی دایکه داود دوروش تابستان 6139.
Presentation transcript:

COMP519: Web Programming Autumn 2007 Perl Tutorial: The very beginning A basic Perl Program The first line Comments and statements Simple printing Running the program Scalar Variables Operations and assignment Interpolation Exercise Array variables Array assignments Displaying arrays Exercise

Perl زبان برنامه نویسی Perl در سال 1980 توسط لاری وال ابداع شد. قرار است Perl شکاف موجود بین زبانهای سطح بالا و سطح پایین را پر نماید. Perl مخصوصا جهت پردازش رشته ها و داده ای متنی بسیار مناسب است. جهت پردازش متون استفاده از عبارات منظم (Regular expressions) دارای انعطاف زیادی است. می توان از Perl جهت برنامه نویسی CGI استفاده کرد.

A Basic Program هر برنامه زبان Perl با خط #!/usr/local/bin/perlشروع می گردد ( یا #!/usr/bin/perl بسته به تنظیمات سرور محلی). به این کار shebang می گویند. برای اضافه کردن توضیحات تک خطی از # استفاده می شود. هر عبارت زبان Perl با ; خاتمه می یابد. تابع print جهت چاپ کردن خروجی استفاده می شود. #!/usr/local/bin/perl # basic01.pl COMP519 # Program to do the obvious # print 'Hello world.'; # Print a message در اینجا یک برنامه ساده را جهت شروع مشاهده می کنید:

Running the Program برای اجرای Perl از Linux استفاده کنید. از یک ویرایشگر متن استفاده نمایید. فایل را اجرایی کنید.  دستور chmod u+x progname را اجرا کنید. برای اجرای برنامه دستور perl progname یا./progname را در خط فرمان تایپ کنید. برای فعال کردن اخطارها از دستور perl -w progname استفاده کنید. برای فعال کردن debugger از دستور perl -d progname استفاده کنید. bash-2.05b$ perl basic01.pl Hello world.bash-2.05b$

Scalar Variables: Declaration متغییر با علامت $ شروع می شوند و می توانند از رشته ها و اعداد نگهداری کنند. نوع یک متغییر وابسته به داده ای است که نگهداری میکند و در حین اجرا قابل تغییر است. $priority = 9; $priority = 'high'; $priority = “high”; Perl اعداد را بصورت رشته نیز می پذیرد. $priority = '9'; $default = '0009'; اسم متغییر ها می تواند شامل اعداد و حروف و _ باشد اما نباید با عدد شروع شود. Perl به بزرگی و کوچکی حروف حساس است. پس $a و $A متفاوت هستند. $_ یک متغییر مخصوص است که بعدا در مورد آن بیشتر بحث خواهیم کرد.

Operations and Assignment عبارات ریاضی در Perl : $a = 1 + 2; # Add 1 and 2 and store in $a $a = 3 - 4; # Subtract 4 from 3 and store in $a $a = 5 * 6; # Multiply 5 and 6 $a = 7 / 8; # Divide 7 by 8 to give $a = 9 ** 10; # Nine to the power of 10 $a = 5 % 2; # Remainder of 5 divided by 2 ++$a; # Increment $a and then return it $a++; # Return $a and then increment it --$a; # Decrement $a and then return it $a--; # Return $a and then decrement it رشته ها در Perl : $a = $b. $c; # Concatenate $b and $c $a = $b x $c; # $b repeated $c times انتساب در Perl : $a = $b; # Assign $b to $a $a += $b; # Add $b to $a $a -= $b; # Subtract $b from $a $a.= $b; # Append $b onto $a دقت کنید که عبارت $a = $b باعث می شود که ابتدا یک کپی از $b درست شود و سپس به $a اختصاص داده می شود. لذا تغییرات بعدی $b روی $a تاثیری ندارد. برای دیدن بقیه عملگر ها دستور man perlop را اجرا کنید.

Interpolation دقت کنید دستور print '$a and $b'; دقیقا خود رشته $a and $b را چاپ می کند. برای چاپ عبارت apples and pears از دستور print "$a and $b"; استفاده کنید. علامت " باعث می شود که متغییرها و عباراتی مثل \n و \t تفسیر شوند. #!/usr/local/bin/perl # basic02.pl COMP519 $a = 'apples'; $b = 'pears'; print $a.' and '.$b; #!/usr/local/bin/perl # basic03.pl COMP519 $a = 'apples'; $b = 'pears'; print “$a and $b”; bash-2.05b$ perl basic02.pl apples and pearsbash-2.05b$ bash-2.05b$ perl basic02.pl apples and pearsbash-2.05b$

Exercise در این برنامه عبارت Hello world. به یک متغییر انتساب و سپس به همراه خط جدید چاپ می شود. #!/usr/local/bin/perl # basic04.pl COMP519 $message = 'Hello world.'; print “$message \n”; # Print a message bash-2.05b$ perl basic04.pl Hello world. bash-2.05b$

Example #!/usr/local/bin/perl # basic05.pl COMP519 print '007',' has been portrayed by at least ', 004, ' actors. '; print "\n"; print 7+3, ' ', 7*3, ' ', 7/3, ' ', 7%3, ' ', 7**3, ' '; print "\n"; $x = 7; print $x; print "\n"; print ' Doesn\'t resolve variables like $x and backslashes \n. '; print "\n"; print " Does resolve $x and backslash\n"; $y = "A line containing $x and ending with line feed.\n"; print $y; $y = "Con". "cat". "enation!\n"; print $y; bash-2.05b$ perl basic05.pl 007 has been portrayed by at least 4 actors Doesn't resolve variables like $x and backslashes \n. Does resolve 7 and backslash A line containing 7 and ending with line feed. Concatenation! bash-2.05b$

String Functions اگر cube اسم یک تابع باشد آنرا به دو صورت می شود صدا زد: cube(x) یا cube x در جدول زیر تعدادی از توابع که برای کار کردن با رسته ها استفاده می شوند آورده شده اند : NameParametersResult chomp(a string)the string w/terminating newline characters removed length(a string)the number of characters in the string lc(a string)the string with uppercase letters converted to lower uc(a string)the string with lowercase letters converted to upper hex(a string)the decimal value of the hexadecimal number in the string join(a char. and a list of strings) the strings concatenated together with the character inserted between them q(a string)places single quotes around the string qq(a string)places double quotes around the string

Array Variables اسم هر آرایه از متغییرها شروع می شود. دقت کنید که در کد زیر به از $ استفاده کرده ایم چون می خواستیم که به یک عنصر از آرایه دسترسی پیدا کنیم. Perl فقط از آرایه های تک بعدی پشتیبانی می کند. (برای آرایه های چند بعدی از ارجاع استفاده می = ("apples", "pears", "eels"); # a three element = ("whistle", "flute"); # a two element list $food[2] # returns = ("whistle", = "harp"); # combines = ("organ", "whistle", "flute", "harp"); # is the = qq(organ whistle flute harp); # is the same

Push and Pop = ("apples", "pears", "eels"); "eggs"); # pushes eggs onto the end "eggs", "lard"); # pushes two items ("eggs", "lard")); # pushes two # pushes the items returns the length of the new list برای اضافه کردن به آخر آرایه از push استفاده کنید. برای حذف کردن از آخر آرایه از pop استفاده = ("apples", "pears", "eels"); $grub = # Now $grub = "eels“ shift و unshift بصورت مشابه کار می کنند اما روی ابتدای لیست عمل می کنند.

Array Assignments ($a, $b) = ($c, $d); # Same as $a=$c; $b=$d; ($a, $b) # $a and $b are the first two items # $a is the first item and is a list of the others $a) and # $a is undefined, that form is best avoided ($a, $b) = ($b, $a); # swaps the values of $a and $b (since # Perl creates the whole list before the # assignment statement) $f= $#food; # assigns the index of the last element array $f # assigns the length $f = # turns the list into a string with a space between each element. # This space can be replaced by any other string # by changing the value of the special (built-in) $" variable. می توان دستورات انتساب چندگانه داشت: انتساب آرایه به یک متغییر:

Displaying Arrays #!/usr/local/bin/perl # basic06.pl = ("apples", "pears", "eels"); # By itself print "\n"; print # Embedded in double quotes print "\n"; $f=$food; print "$f \n"; # In a scalar context bash-2.05b$ perl basic06.pl applespearseels 3