Reverse does not use $ _ implicitly in the context of the list, is this an error?

@array = reverse; and @array = reverse $_; 

Both are different. @array = reverse does not use $_ implicitly. We must explicitly declare $_ . This is a very strange case when $_ not used by default. This is mistake?

+1
source share
2 answers

As far as I understand from the reverse documentation , reverse works with arrays, so it should use @_ , not scalar $_ ?

The documentation says: "Used without arguments in a scalar context , reverse() overrides $_ ." [Emphasis added]

 $_ = "dlrow ,olleH"; print reverse; # No output, list context print scalar reverse; # Hello, world 
+9
source

All that is in the official documentation is the Perl specification. If Perl does what the documents say, it should do it, but that is not an error. This is a decision for language and decision making.

+4
source

Source: https://habr.com/ru/post/899906/


All Articles