Perl引用简单使用

来源:互联网 发布:ubuntu编辑只读文件 编辑:程序博客网 时间:2024/06/05 04:53

#!/usr/bin/perl
my @all_with_name;

sub initialize_provisions_list{
    my @skipper = qw(bule_shirt hat jacket preserver sunscreen);
    my @skipper_with_name = ('The Skipper', /@skipper);

    my @professor = qw(sunscreen water_bottle slide_rule batteries);
    my @professor_with_name =('The professor',/@professor);

    my @gilligan = qw(red_shirt hat lucky_socks water_bottle);
    my @gilligan_with_name = ('The gilligan',/@gilligan);

    @all_with_name =(
        /@skipper_with_name,       
        /@professor_with_name,
        /@gilligan_with_name,
    );
}

initialize_provisions_list();

print "${$all_with_name[0]->[1]}[0]/n";

 

从这里我们得到是blue_shirt,虽然函数已经退出,但我们从侧面可以得到内存的数据

我们可以简单的改一下:

sub get_provisions_list{

     ......

     ......

     ......

     return(

           /@skipper_with_name,

          /@professor_with_name,

          /@gilligan_with_name,

     );

}

 

my @all_with_names = get_provisions_list();

原创粉丝点击