Implement apply and rudimentary read-line
This commit is contained in:
parent
ba0915f384
commit
f576081d22
1 changed files with 17 additions and 0 deletions
|
@ -409,6 +409,23 @@ my %stdctx = (
|
||||||
return length($a);
|
return length($a);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
'apply' => sub {
|
||||||
|
my ($fn, $lst) = @_;
|
||||||
|
die "apply: First operand must be a function"
|
||||||
|
unless ref($fn) eq "CODE";
|
||||||
|
die "apply: Second operand must be a list"
|
||||||
|
unless ref($lst) eq "ARRAY";
|
||||||
|
|
||||||
|
return $fn->(@$lst);
|
||||||
|
},
|
||||||
|
|
||||||
|
# Input/output
|
||||||
|
'read-line' => sub {
|
||||||
|
my $fh = shift;
|
||||||
|
my $val = defined($fh) ? <$fh> : <>;
|
||||||
|
chomp $val;
|
||||||
|
return $val;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
sub parser {
|
sub parser {
|
||||||
|
|
Loading…
Reference in a new issue