|
|
Perl - Private Variables in Function - Perl
|
Views : 390
|
|
Tagged in : Perl
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
Perl - Private Variables in Function
One private variable is the '@_' and access to it's elements by $_[x]. You can create your private variables by use of the my operator. my variables are strictly used within the subroutine where there are defined. my variables can only be scalar, array or hash. The following example uses variable names that it more readable. In addition it passes an extra value that is used for a limits check.
sub bigger_than {
my ($limit, @values);
($limit, @values) = @_;
my(@result);
foreach $_ (@values) {
if ($_ > $limit) {
push(@result, $_);
}
}
return @result;
}
@new = bigger_than(100, @list); # @new contains all values in @list >100
@this = bigger_than(5,1,5,15,30); # @this = 15,30 |
|
By Geethalakshmi, On - 2010-09-17 |
|
|
|