Home > other >  What is the difference about subroutine has the * prototype between Perl 5.22 and before?
What is the difference about subroutine has the * prototype between Perl 5.22 and before?

Time:09-22

I read the Perl document about Changes to the * prototype

Changes to the * prototype
The * character in a subroutine's prototype used to allow barewords to take precedence over most, but not all, subroutine names. It was never consistent and exhibited buggy behavior.

Now it has been changed, so subroutines always take precedence over barewords, which brings it into conformity with similarly prototyped built-in functions

Code example:

sub splat(*) { ... }
sub foo { ... }
splat(foo); # now always splat(foo())
splat(bar); # still splat('bar') as before
close(foo); # close(foo())
close(bar); # close('bar')

Can anyone explain to me the difference? Thank for any help.

CodePudding user response:

All that perldelta entry is stating is that when foo() is a predefined function then, prior to 5.22, the call splat(foo) might have been interpreted by the parser as either splat(foo()) or splat('foo'), but you couldn't easily tell which. Now it will always be seen as splat(foo()).

  •  Tags:  
  • perl
  • Related