ประโยคตรวจสอบเงื่อนไข ในภาษา Perl นั้นมีคำสั่งตรวจสอบเงื่อนไข ดังนี้

- if ซึ่งจะแบ่งแยกออกเป็น

- คำสั่ง if {}

if ($number == 1) {

}

if ($string eq "welcome") {

}

- คำสั่ง if {} else {}

if ($number == 1) {

} else {

}

- คำสั่ง if {} elsif {}

if ($number == 1) {

} elsif ($number == 2) {

}

- คำสั่ง if {} elsif {} else {}

if ($number == 1 ) {

} elsif ($number == 2) {

} else {

}

- unless คือ การตรวจสอบเงื่อนไขอีกอย่างนึง ที่ใช้ในทางตรงข้ามกับ if (หรืออีกนัยนึงมีความหมายเท่ากับ else)

unless ($number == 1) {

}

# หมายความว่า ถ้าตัวแปร $number ไม่เท่ากับ 1

edit @ 14 Sep 2009 18:23:03 by Genetic

Comment



smilebig smileopen-mounthed smileconfused smilesad smileangry smiletonguequestionembarrassedsurprised smilewinkdouble winkcry

Tweet