于 2012-2-7 15:45, lina 写道:
I am sorry, still don't get.

$year = shift

part


Try with this code:

use strict;
my $month = "December";
my $year = "2007" ;

header($month,$year);

sub header {
        print '@_ is: ' . "@_\n";
        my $month = shift ;
        print '@_ is: ' . "@_\n";
        my $year = shift ;
        print '@_ is: ' . "@_\n";
}


The output:

@_ is: December 2007
@_ is: 2007
@_ is:


"shift" means "shift @_" in Perl.
So the first shift, $month get the value shifted from @_, and the first element in @_ get removed. the second shift, $year get the value shifted from @_, the second element in @_ get removed.
Since @_ has only two elements, so after two shift, it becomes null.
That's all.

HTH.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to