diff options
author | Chip Salzenberg <chip@perl.com> | 1997-04-30 00:00:00 +1200 |
---|---|---|
committer | Chip Salzenberg <chip@atlantic.net> | 1997-04-30 00:00:00 +1200 |
commit | 6da72b644b845971d5b417f3c6f5590e23084bcd (patch) | |
tree | 322d1e0b1a154d0b12f1fcc49838fe9a9aa4288c /pod | |
parent | 404b15a1d1b7c56f5774b99fd0d4b6854620182b (diff) | |
download | perl-6da72b644b845971d5b417f3c6f5590e23084bcd.tar.gz |
Support C< $coderef->($x,$y) >
Randal Schwartz said:
> Some time in October, 1994, Larry Wall said:
> > : All other references you can follow with ->, what about code refs?
> > Aw, look, I'd really like that feature in, but I think it's a bit
> > too close to the release for that.
> Hey Chip,
> Look, Larry said he'd really like that feature
Larry said that? That change is like two lines, it's in!
Tricked-into-doing-by: Randal Schwartz <merlyn@stonehenge.com>
Diffstat (limited to 'pod')
-rw-r--r-- | pod/perldelta.pod | 18 | ||||
-rw-r--r-- | pod/perldsc.pod | 4 | ||||
-rw-r--r-- | pod/perlref.pod | 13 | ||||
-rw-r--r-- | pod/perltoc.pod | 4 |
4 files changed, 31 insertions, 8 deletions
diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 930773ca02..f4a4d232ca 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -190,6 +190,24 @@ It is now possible to build Perl with AT&T's sfio IO package instead of stdio. See L<perlapio> for more details, and the F<INSTALL> file for how to use it. +=head2 New and changed syntax + +=over + +=item $coderef->(PARAMS) + +A subroutine reference may now be suffixed with an arrow and a +(possibly empty) parameter list. This syntax denotes a call of the +referenced subroutine, with the given parameters (if any). + +This new syntax follows the pattern of C<$hashref-E<gt>{FOO}> and +C<$aryref-E<gt>[$foo]>; now, C<&$subref($foo)> may now be written +C<$subref-E<gt>($foo)>. All of these arrow terms may be chained; +thus, C<&{$table-E<gt>{FOO}}($bar)> may now be written +C<$table-E<gt>{FOO}->($bar)>. + +=back + =head2 New and changed builtin constants =over diff --git a/pod/perldsc.pod b/pod/perldsc.pod index aea53ae442..48750dd5de 100644 --- a/pod/perldsc.pod +++ b/pod/perldsc.pod @@ -698,8 +698,8 @@ many different sorts: print $rec->{LOOKUP}{"key"}; ($first_k, $first_v) = each %{ $rec->{LOOKUP} }; - $answer = &{ $rec->{THATCODE} }($arg); - $answer = &{ $rec->{THISCODE} }($arg1, $arg2); + $answer = $rec->{THATCODE}->($arg); + $answer = $rec->{THISCODE}->($arg1, $arg2); # careful of extra block braces on fh ref print { $rec->{HANDLE} } "a string\n"; diff --git a/pod/perlref.pod b/pod/perlref.pod index cf793652f7..6aa086088d 100644 --- a/pod/perlref.pod +++ b/pod/perlref.pod @@ -318,14 +318,15 @@ it's presumably referencing. That would be case 3. =item 3. -The case of individual array elements arises often enough that it gets -cumbersome to use method 2. As a form of syntactic sugar, the two -lines like that above can be written: +Subroutine calls and lookups of individual array elements arise often +enough that it gets cumbersome to use method 2. As a form of +syntactic sugar, the examples for method 2 may be written: - $arrayref->[0] = "January"; - $hashref->{"KEY"} = "VALUE"; + $arrayref->[0] = "January"; # Array element + $hashref->{"KEY"} = "VALUE"; # Hash element + $coderef->(1,2,3); # Subroutine call -The left side of the array can be any expression returning a reference, +The left side of the arrow can be any expression returning a reference, including a previous dereference. Note that C<$array[$x]> is I<NOT> the same thing as C<$array-E<gt>[$x]> here: diff --git a/pod/perltoc.pod b/pod/perltoc.pod index 80004683f1..7f1973d366 100644 --- a/pod/perltoc.pod +++ b/pod/perltoc.pod @@ -924,6 +924,10 @@ CGI script to do bad things? =item Internal change: PerlIO abstraction interface +=item New and changed syntax + +$coderef->(PARAMS) + =item New and changed builtin constants __PACKAGE__ |