자바스크립트를 허용해주세요.
[ 자바스크립트 활성화 방법 ]
from Mohon Aktifkan Javascript!
 

[Perl] 2장 Perl - 변수와 데이터 타입

728x90

1️⃣ 스칼라 변수 ( $ )

Perl의 스칼라 변수는 하나의 값(숫자 혹은 문자열)을 저장하며 변수 앞에 기호를 붙힙니다.

my $name = "Sally";
my $age = 30;
my $hobby = "reading";
my $blog = "https://sallysblog.example.com";

print "$name is $age years old and enjoys $hobby, Check out her blog at $blog.\n"
// "Sally is 30 years old and enjoys reading, Check out her blog at https://sallysblog.example.com."

2️⃣ 배열 ( @ )

배열은 여러 개의 값을 순서대로 저장한 것이며, 변수명 앞에 @ 기호를 사용합니다 

my @toast = ("butter", "jam", "apple slices", "peanut butter");
print $toast[0]; # "butter"
print $toast[2]; # "apple slices"

# 배열 전체 출력
print "@toast\n"; # "butter jam apple slices peanut butter"

3️⃣ 해시 ( % )

해시는 키-값을 쌍으로 저장하는 자료구조로 변수명 앞에 %를 기호로 붙힙니다.

my %movie_ratings = (
    "Inception" => 8.8,
    "Jurassic Park" => 8.1,
    "Avengers: Endgame" => 8.4,
    "Taken" => 7.8
);

print "Rating of Inception is $movie_ratings{'Inception'}\n"; # "Rating of Inception is 8.8"

# 해시 전체 출력
while (my ($movie, $rating) = each %movie_ratings) {
    print "$movie has a rating of $rating\n"
} 
# "Rating of Inception is 8.8"
# "Avengers: Endgame has a rating of 8.4"
# "Inception has a rating of 8.8"
# "Jurassic Park has a rating of 8.1"
# "Taken has a rating of 7.8"

4️⃣ 요약

  • 스칼라: $변수(하나의 값)
  • 배열: @변수(여러 값, 인덱스 사용)
  • 해시; %변수(키-값 쌍, 키로 접근)

 

 

GitHub - Koras02/Perl-Bloging: https://thinky.tistory.com/category/Back-End/Perl

https://thinky.tistory.com/category/Back-End/Perl. Contribute to Koras02/Perl-Bloging development by creating an account on GitHub.

github.com

 

728x90
LIST

'Back-End > Perl' 카테고리의 다른 글

[Perl] 5장 문자열 처리 기본  (0) 2025.08.15
[Perl] 4장 기본 연산자  (2) 2025.08.13
[Perl] 3장 Perl - 주석과 들여쓰기  (0) 2025.08.12
[Perl] 1장 Perl이란?  (0) 2025.08.10