Recommanded Free YOUTUBE Lecture: <% selectedImage[1] %>

shift 함수

perl의 shift() 함수에 대해서 좀 자세히 알아봐야 할 것 같아서..

설명

shift()는 perl의 배열관련 함수중 하나로, 배열(:12)의 첫번째 값을 리턴하고 배열에서 제거한다. 배열의 왼쪽으로 밀어내는 느낌이라고나 할까? 제일 마지막의 원소를 리턴하고 제거하는 pop()과 반대의 일을 한다고 보면 될 것 같다.

  @myNames = ('yun', 'dream', 'ida');
  $firstName = shift(@myNames);

예제

#!/usr/bin/perl

@array = (1..5);
while ($element = shift(@array)) {
    print("$element - ");
}
print("The End\n");