您的位置:寻梦网首页编程乐园CGI编程Zhanshou's CGI Tutorial

Subroutines


Perl defines subroutines in the following form:
 sub SUBNAME { 
        STATEMENTS; 
    } 
Subroutines are invoked in this way:
    &SUBNAME(arg1,arg2,etc); 
    # - or - (if the subroutine takes no arguments. 
    &SUBNAME; 
    # return values are used just like any other value  
    $returnvalue = &SUBNAME(@values); 

Example

    # define an error  routine: 
    sub error { 
        ($message) = @_; 
        print("<b>ERROR:<b>", 
        $message, 
        "<p>Contact the author of the previous page for assistance\n"); 
        exit(0); 
    } 
    if ( ! $recipient ) { 
        # the form did not have a to field 
        # modify this text appropriately 
        &error("No Return Address"); 
    } 

Previous Page Table of Content Next Page