Example 6-2. examples/subroutines/optional_params.p6
#!/usr/bin/perl6
# search the text within a file return 1 if found, 0 if not
sub search ($text, $file) {
my $fh open $file, :r err die;
for $fh.readline -> $line {
if index($line, $text) > -1 {
return 1;
}
}
return 0;
}
# optional parameter
sub search($text, $file, $all?) {
my $fh open $file, :r err die;
my $cnt = 0;
for $fh.readline -> $line {
if index($line, $text) > -1 {
return 1 if not $all;
$cnt++;
}
}
return $cnt;
}
| Prev | Home (Copyright Gabor Szabo) Perl Training Israel | Next |
| Subroutines in Perl6 | Up | Subroutines |