GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
STYLE.PERL(7) FreeBSD Miscellaneous Information Manual STYLE.PERL(7)

style.perl
FreeBSD Perl ¿ø½Ã ÆÄÀÏÀÇ ½ºÅ¸ÀÏ °¡À̵å

ÀÌ ÆÄÀÏÀº FreeBSD ¼Ò½º Æ®¸®ÀÇ perl ½ºÅ©¸³Æ®¿¡ ¹Ù¶÷Á÷ÇÑ ½ºÅ¸ÀÏÀ» ¸í±âÇØ ÀÖ½À´Ï´Ù.
# 
# Perl ¸¦ À§ÇÑ ½ºÅ¸ÀÏ °¡À̵åÀÔ´Ï´Ù. Ä¿³ÎÀÇ ½ºÅ¸ÀÏ °¡À̵忡 ±Ù°ÅÇÏ°í ÀÖ½À´Ï´Ù. 
# 
 
# 
# ¸Å¿ì Áß¿äÇÑ 1 ÇàÀÇ ÄÚ¸àÆ®´Â ÀÌ¿Í °°ÀÌ ÇÕ´Ï´Ù. 
# 
 
# ´ëºÎºÐÀÇ 1 Çà ÄÚ¸àÆ®´Â ÀÌ¿Í °°ÀÌ ÇÕ´Ï´Ù. 
 
# º¹¼öÇà¿¡ °ÉÄ¡´Â ÄÚ¸àÆ®´Â ÀÌ¿Í °°ÀÌ ÇÕ´Ï´Ù. ½ÇÁ¦ÀÇ ¹®ÀåÀ» ¾¹´Ï´Ù. ½ÇÁ¦ÀÇ 
# ´Ü¶ôÀ¸·Î º¸À̵µ·Ï(µíÀÌ) ¹¯¾î °©´Ï´Ù.
¸ðµç ½ºÅ©¸³Æ®¿¡´Â ½ºÅ©¸³Æ®ÀÇ ¼±µÎ¿¡ ÀúÀÛ±Ç ºí·Ï°ú ±× ½ºÅ©¸³Æ®°¡ ¹«¾ùÀ» ÇÏ´Â °ÍÀΰ¡¸¦ ±â¼úÇÑ ÄÚ¸àÆ® ºí·ÏÀ» µÎ¾î¾ß ÇÑ´Ù ÀÔ´Ï´Ù.
#! /usr/bin/perl -w 
 
# ÀúÀÛ±Ç 
# ºí·Ï 
 
# ÀÌ ½ºÅ©¸³Æ®´Â Ç¥ÁØ ÀÔ·ÂÀ¸·ÎºÎÅÍ ³°Àº Ä¿³Î ¼³Á¤ ÆÄÀÏÀ» Àоîµé¿©, 
# Ç¥ÁØ Ãâ·Â¿¡ »õ·Î¿î Çü½ÄÀÇ ÈùÆ® ÆÄÀÏÀ» Ãâ·ÂÇÕ´Ï´Ù.
¸ðµç ½ºÅ©¸³Æ®´Â strict(3) ¸ðµâÀ» »ç¿ëÇØ °æ°í¾øÀÌ µ¿ÀÛÇÏÁö ¾ÊÀ¸¸é ¾ÈµË´Ï´Ù. ¿¹¸¦ µé¸é, ´ÙÀ½°ú °°ÀÌ ÇÕ´Ï´Ù:
#! /usr/bin/perl -w 
 
# ÀúÀÛ±Ç, ½ºÅ©¸³Æ®ÀÇ ³»¿ë ±â¼ú, ±× ¿Ü 
 
use strict; 
...
°¡´ÉÇÑ Àå¼Ò¿¡¼­´Â ½ºÅ©¸³Æ®¸¦ taint (¿À¿°) ¸ðµå·Î ÇØ µ¿ÀÛ½ÃÄÑ ÁÖ¼¼¿ä. ÀÌ°ÍÀº perlsec(1) ±×¸®°í ¹®¼­È­ µÇ°í ÀÖ½À´Ï´Ù.
#! /usr/bin/perl -wT
¸ÞÀÎ ÇÁ·Î±×·¥Àº MAIN: ¿Í label µÈ ºí·Ï¿¡ µÎ¾î¾ß ÇÕ´Ï´Ù. ÀÌ°Í¿¡ ÀÇÇØ Å« perl ½ºÅ©¸³Æ®·Î °³½ÃÁ¡À» ½Äº°ÇÏ´Â °ÍÀÌ ¿ëÀÌÇÏ°Ô µÇ¾î, ¶Ç ¸ÞÀÎ ÇÁ·Î±×·¥¸¸À¸·Î »ç¿ëµÇ´Â º¯¼ö¿¡ ´ëÇؼ­ ½ºÄÚÇÁ¸¦ ÁÝ´Ï´Ù.
MAIN:{ 
	print(foo("/usr/bin/man", "7", "style.perl")); 
	exit(0); 
}
¸ðµç ½áºê·çƾÀº perlsub(1) ±×¸®°í Á¤Àǵǰí ÀÖ´Â °Í °°Àº prototype Àμö¸¦ »ç¿ëÇØ Á¤ÀÇÇØ¾ß ÇÕ´Ï´Ù.
sub foo($@) { 
	my $cmd = shift; 
	my @args = @_; 
}
¸ðµç º¯¼ö´Â »ç¿ëÇϱâ Àü¿¡ Á¤ÀÇÇØ¾ß ÇÕ´Ï´Ù. ÀÌ°ÍÀº use strict ¾Æ·¡¿¡¼­ ÀÌ¿ëÇÏ´Â °æ¿ì´Â °­Á¦´çÇÕ´Ï´Ù.
·ÎÄà º¯¼öÀÇ ½ºÄÚÇÁÀÇ Á¤ÀÇ¿¡´Â local $variable (Àº)´Â ¾Æ´Ï°í my $variable (À»)¸¦ ÀÌ¿ëÇØ¾ß ÇÕ´Ï´Ù. local ¼±¾ðÀº ±×°ÍÀÌ ÇÊ¿äÇÏ°Ô µÇ´Â Àå¸é¿¡°Ô¸¸ »ç¿ëÇØ, µðÆúÆ®¿¡¼­´Â »ç¿ëÇØ¾ß ÇÏ´Â °ÍÀº ¾ø½À´Ï´Ù. ¸¹Àº perl4 ½ºÅ©¸³Æ®¿¡¼­´Â, my Á¤ÀÇ°¡ perl5 ÀÌÀü¿¡´Â Á¸ÀçÇÏÁö ¾Ê¾Ò´Ù°í ÇÏ´Â ÀÌÀ¯·Î local (À»)¸¦ »ç¿ëÇÏ°í ÀÖ½À´Ï´Ù.
¸¹Àº °æ¿ì, ±Û·Î¹ú º¯¼ö´Â ÄÚµåÀÇ ¼±µÎ¿¡¼­ vars(3) Á¤ÀÇ ºí·ÏÀ» »ç¿ëÇØ Á¤ÀÇÇØ¾ß ÇÕ´Ï´Ù:
use vars qw($globalscalar @globalarray %globalhash);
°æ¿ì¿¡ µû¶ó¼­´Â ½ºÅ©¸³Æ®ÀÇ ¼±µÎ¿¡¼­ vars(3) ¼±¾ðÀº ¾Æ´Ï°í my ¹®ÀåÀ» ÀÌ¿ëÇÏ´Â °ÍÀÌ ÀûÇÕÇÑ Àϵµ ÀÖ½À´Ï´Ù.
¸ðµç º¯¼ö¿¡´Â ÄÚ¸àÆ®¸¦ Àû¾î¾ß ÇÕ´Ï´Ù.
sub foo($@) { 
	my $cmd = shift;	# ½ÇÇàÇÏ´Â ¸í·É 
	my @args = @_;		# $cmd ¿¡ÀÇ Àμö 
}
·ÎÄà º¯¼ö´Â °øÇà¿¡ ÀÇÇØ ÇÔ¼öÀÇ Àμö¿Í ºÐ¸®ÇØ¾ß ÇÕ´Ï´Ù:
sub foo($@) { 
	my $cmd = shift;	# ½ÇÇàÇÏ´Â ¸í·É 
	my @args = @_;		# command ¿¡ÀÇ Àμö 
 
	my $pid;		# ÀÚÀÇ PID 
	local *PIPE;		# ÆÄÀÌÇÁ 
	my $output;		# ¸í·É·ÎºÎÅÍÀÇ Ãâ·Â 
}
°¡´ÉÇÑ ¶§¿¡´Â ¾ðÁ¦¶óµµ, ÄÚµå´Â ÄÚµå checker perl -wc script.pl ¶Ç´Â perl -wcT script.pl (À»)¸¦ Åë°ú½ÃÄÑ ÁÖ¼¼¿ä. ±× ¶§, °æ°í°¡ »ý¼ºµÇ¾î¼­´Â ¾ÈµË´Ï´Ù.
Àε§Æ®´Â 8 ij¸¯ÅÍÀÇ ÅÇÀÔ´Ï´Ù. Á¦ 2 ·¹º§ÀÇ Àε§Æ®´Â 4 ij¸¯ÅÍÀÇ ½ºÆäÀ̽ºÀÔ´Ï´Ù.
while (cnt < 20) { 
	z = a + really + long + statement + that + needs + 
	    two lines + gets + indented + four + spaces + 
	    on + the + second + and + subsequent + lines. 
}
°ø¹é ij¸¯Å͸¦ ÁÙ ³¡¿¡ Ãß°¡ Çؼ­´Â ¾ÈµË´Ï´Ù. ¶Ç, Àε§Æ®¸¦ Çü¼ºÇϱâ À§Çؼ­, ½ºÆäÀ̽ºÀÇ ¾Õ¿¡´Â ÅǸ¸À» »ç¿ëÇØ ÁÖ¼¼¿ä. ÅÇÀÌ ³º´Â ÀÌ»óÀÇ ½ºÆäÀ̽º ¹× ÅÇÀÇ Àü¿¡ ½ºÆäÀ̽º¸¦ »ç¿ëÇØ ¾ÈµË´Ï´Ù.
braceÀÇ °³½Ã´Â Á¦¾îÇàÀÇ ¸¶Áö¸·¿¡ ³õ¿©Áý´Ï´Ù. else ¿Í elsif ´Â Á÷ÀüÀÇ if ¶Ç´Â elsif ºí·ÏÀÇ Á¾·á brace¿Í °°Àº Çà¿¡ ³õ¿©Áý´Ï´Ù:
sub foo($@) { 
	my $cmd = shift;            # ½ÇÇàÇÏ´Â ¸í·É 
	my @args = @_;              # ¸í·É¿¡ÀÇ Àμö 
 
	my $pid;                    # ÀÚÀÇ PID 
	local *PIPE;                # ÆÄÀÌÇÁ 
	my $output;                 # ¸í·É·ÎºÎÅÍÀÇ Ãâ·Â 
 
	unless (defined($pid = open(PIPE, "-|"))) { 
		die("open(): $! \n"); 
	} elsif ($pid == 0) { 
		exec($cmd, @args); 
		die("exec(): $! \n"); 
	} 
	$output = ""; 
	while (<PIPE>) { 
		$output . = $_; 
	} 
	waitpid($pid, 0); 
	if ($?  & 0xff) { 
		die("$cmd caught a signal " .  ($?  & 0x7f) .  "\n"); 
	} elsif ($? ) { 
		die("$cmd returned exit code " .  ($?  >> 8) .  "\n"); 
	} 
	return $output; 
}
°¡´ÉÇÑ Àå¼Ò¿¡¼­´Â, ½ºÅ©¸³Æ®´Â Ç¥ÁØ ¸ðµâÀ» »ç¿ëÇØ, Äڵ带 ±× ÀÚ¸®¿¡ °íÃÄ ½á¼­´Â ¾ÈµË´Ï´Ù. ÀÌ°ÍÀ» ÃËÁøÇϱâ À§Çؼ­, CPAN ¸ðµâÀ» ±âº» ½Ã½ºÅÛ¿¡ ¼öÁß¿¡ ³Ö´Â °ÍÀÌ ÀûÇÕÇÑ °æ¿ì°¡ ÀÖÀ»Áöµµ ¸ð¸¨´Ï´Ù.
ÀûÀýÇÑ °÷¿¡¼­´Â, chop (Àº)´Â ¾Æ´Ï°í chomp (À»)¸¦ »ç¿ëÇØ ÁÖ¼¼¿ä.
°¡µ¶¼ºÀÌ ´õÇÏ´Â °æ¿ì¿¡´Â if (! ...) (Àº)´Â ¾Æ´Ï°í unless (À»)¸¦ »ç¿ëÇØ ÁÖ¼¼¿ä.
ÀÌ °¡À̵忡 ¸ð¼øµÇÁö ¾Ê´Â ¹üÀ§¿¡¼­ perlstyle(1) (À»)¸¦ Àоî Larry Wall ÀÇ Ãßõ ½ºÅ¸ÀÏÀ» ä¿ëÇØ ÁÖ¼¼¿ä.

perlsec(1), perlstyle(1), style(9)

ÀÌ ¸Þ´º¾ó ÆäÀÌÁö´Â, FreeBSD ÀÇ style(9) ¸Þ´º¾ó ÆäÀÌÁö¿¡ Å©°Ô ±âÃʸ¦ µÎ°í ÀÖ½À´Ï´Ù.
October 16, 2000 FreeBSD 12.0-RELEASE

Search for    or go to Top of page |  Section 7 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.