27 April 2011

printf VS sprintf

ความแตกต่างของ printf กับ sprintf คือ sprintf มี null character (\0) ต่อท้าย

print ใน perl

#!c:\perl\bin\perl.exe

print "content-type:text/html\n\n";

#print ค่าของตัวแปร
print "Server $ENV{'SERVER_NAME'}\n\n";

#print ตัวอักษรด้วย (')
print 'We are running Perl version:';
print $^V."\n\n";

#print multiline
print < The perl binary : $^X
The perl script : $0
EOF

passing parametor to subroutines

การส่งค่า parametor ใน perl

รับเข้ามาเป็น array ใช้ @_
รับค่าแต่ละตัวตามลำดับ $_[1],$_[2],.....

การใช้ quote ใน perl

double qoute (") ค่าที่อยู่ใน doble qoute ถ้าเป็นตัวแปรจะแสดงค่าของตัวแปรนั้นออกมา ถ้าเป็นตัวอักษรพิเศษก็จะแสดงตัวอักษรพิเศษออกมา

single qoute (') ค่าที่อยู่ใน single qoute จะแสดงตามที่อยู่ข้างในทั้งหมด

black qoute (`) ค่าที่อยู่ในนี้คือคำสั่ง shell หรือ dos โดยจะ return ค่าผลลัพธ์ที่ได้ สามารถใช้ตัวแปรมารับค่าได้

#!c:\perl\bin\perl
print "content-type:text/html \n\n";
print "Hello World\n"; #จะได้ Hello World
print 'Hello World\n'; #จะได้ Hello World\n
print `date`; #จะได้ The current date is: Wed 04/27/2011 Enter the new date: (mm-dd-yy)

ผลลัพธ์ใน browser
Hello World Hello World\nThe current date is: Wed 04/27/2011 Enter the new date: (mm-dd-yy)

ผลลัพธ์ใน view->source
Hello World
Hello World\nThe current date is: Wed 04/27/2011
Enter the new date: (mm-dd-yy)

my function ในภาษา perl

การใช้ my function กับตัวแปรใน perl คือการกำหนด variable scope ถ้าเราสร้างตัวแปรที่มีชื่อเหมือนกับ global variable ในฟังก์ชั่นโดยใช้ my ด้วย global variable จะไม่ถูกแก้ไข

#!c:\perl\bin\perl
print "content-type:text/html \n\n";
$myString = "haha";
sub test
{
my $myString = "test";
}
print $myString."->01";
&test();
print $myString."->02";

ผลลัพธ์
haha->01
haha->02

###############################################

#!c:\perl\bin\perl
print "content-type:text/html \n\n";
$myString = "haha";
sub test
{
$myString = "test";
}
print $myString."->01";
&test();
print $myString."->02";

ผลลัพธ์
haha->01
test->02

###############################################

#!c:\perl\bin\perl
print "content-type:text/html \n\n";
my $myString = "haha";
sub test {
$myString = "test";
}
print $myString. "->01";
&test();
print $myString. "->02";

ผลลัพธ์
haha->01
test->02

###############################################

#!c:\perl\bin\perl
print "content-type:text/html \n\n";
my $myString = "haha";
sub test {
my $myString = "test";
}
print $myString. "->01";
&test();
print $myString. "->02";

ผลลัพธ์
haha->01
haha->02

20 April 2011

Method access modifier ใน objective-c

‘-’ in the front of the definition, signifies that the method is an instance method.
‘+’ to define a class method (more on class methods in a future post).

credit : http://macdevelopertips.com/objective-c/objective-c-defining-a-class.html

เปรียบเทียบชื่อ template ของ xcode ios

Cocoa Touch OpenGL Application -> OpenGL ES Application

Cocoa Touch Tab Bar -> Tab Bar Application

Cocoa Touch Utility -> Utility Application

Cocoa Touch Application -> Window-based Application / View based application

Cocoa Touch List -> Navigation based Application