2012-03-25 3 views
3

inbuilt 푸시 기능과 비슷한 기능을 가진 서브 루틴 mypush를 만들려고하는데 아래 코드가 제대로 작동하지 않습니다. 이 라인에서펄에서 함수 프로토 타입

@planets = ('mercury', 'venus', 'earth', 'mars'); 
    myPush(@planets,"Test"); 

    sub myPush (\@@) { 
     my $ref = shift; 
     my @bal = @_; 
     print "\@bal : @bal\nRef : @{$ref}\n"; 
     #... 
    } 

답변

11

:

myPush(@planets,"Test"); 

펄은 아직 프로토 타입을 볼 수 없습니다, 그래서 그것을 적용 할 수 없습니다. (. 당신은 항상 당신이 main::myPush() called too early to check prototype하는 메시지가 나타납니다해야하는, 경고 설정 한 경우) 당신은 전에 서브 루틴 을 만들 수 있습니다

당신은 그것을 사용 : 다른

sub myPush (\@@) { 
     my $ref = shift; 
     my @bal = @_; 
     print "\@bal : @bal\nRef : @{$ref}\n"; 
     #... 
    } 

    @planets = ('mercury', 'venus', 'earth', 'mars'); 
    myPush(@planets,"Test"); 

또는 적어도 프로토 타입으로 사전 선언 : 당신은 기능과 이름을 확인하는 경우

sub myPush (\@@); 

    @planets = ('mercury', 'venus', 'earth', 'mars'); 
    myPush(@planets,"Test"); 

    sub myPush (\@@) { 
     my $ref = shift; 
     my @bal = @_; 
     print "\@bal : @bal\nRef : @{$ref}\n"; 
     #... 
    } 
0

, 당신은 단지 호출하기 전에 앰퍼샌드를 넣을 수 있습니다 :

@planets = ('mercury', 'venus', 'earth', 'mars'); 
&myPush(@planets,"Test"); 

sub myPush (\@@) { 
    my $ref = shift; 
    my @bal = @_; 
    print "\@bal : @bal\nRef : @{$ref}\n"; 
    #... 
}