본문 바로가기
Programming/Perl

perl underground 1-3

by NAMP 2009. 5. 2.

원문: http://www.milw0rm.com/papers/88

 

while loop.

이 루프는 if 제어문 과 비슷하다.

조건이 참이면 코드 블록의 실행을 계속한다.

-----

$i = 0;

while ($i <= 10) {

    print "$i is not more than 10\n";

    $i = $i + 1;

}

-----

결과

 

0 is not more than 10

1 is not more than 10

2 is not more than 10

3 is not more than 10

4 is not more than 10

5 is not more than 10

6 is not more than 10

7 is not more than 10

8 is not more than 10

9 is not more than 10

10 is not more than 10

 

여기서 펄은 다음과 같은 사용하는 것을 제공한다.

"$i = $i + 1"

              "$i += 1"

표현

             더 짧은 동일한 식            

$i = $i + 17

             $i += 17

            

$j = $j * 12

             $j *= 12

            

$variable++; # $variable 증가

$variable--;  # $variable 감소

"$i = $i + 1" 는 다음과 같이 쓸 수 있다. "$i++"

-----

$i = 0;

while ($i <= 10) {

    print "$i is not more than 10\n";

    $i++; #we could also use $i += 1

}

 

 

| 입력 |

펄에게 있어 입력은 쉬운일이다.

아래 예제는 사용자로부터 입력을 받아서 $teh_inputz0r 변수에 저장한다.

-----

chomp($teh_inputz0r = <STDIN>);

-----

chomp 함수는 단순이 문자열 끝부분의 newline 을 제거한다.

 

Jargon: 특수용어, 전문어, 변말, 곁말, 은어

Learn jargon

To understand documentation, you need to know the jargon that it uses.

This jargon is different from other programming languages, so don't think

your Java or C knowledge is any help.

 

무료 온라인 서적 Beginning Perl 을 추천한다.

 

프로그래밍 스타일은 사람의 성향이다.

모든 스타일에 한가지 공통점이 있다. 일관성

 

for (...) {

    unless (foo) {

             # lots of code here

    } else {

             # some code here

    }

}

 

redo, last ,next. 를 사용하면 다음과 같이 바꿀 수 있다.

 

for (...) {

    if (foo) {

             # some code here

             next;

    }

    # lots of code here

}

 

Never ask for help before trying to figure it out on your own.

If you ask for help and you get a reference to documentation as the answer, don't whine, but read that documentation.

Whine : 투덜거림, 불평

 

# Don't be closed minded

 

Repository : (지식, 정보의) 보고

 

CPAN is the single largest repository of freely available code for any language. 

'Programming > Perl' 카테고리의 다른 글

pl- 시저의 암호  (0) 2009.05.16
Perl Underground 2  (0) 2009.05.02
perl underground 1-2  (0) 2009.05.01
perl underground 1-1  (0) 2009.04.30
Package  (0) 2009.04.23

댓글