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

Both are different. @array = reverse doesn't use $_ implicitly. We have to declare $_ explicitly. It's a very strange case where $_ is not being used by default. Is it a bug?

Chankey Pathak
  • 21,187
  • 12
  • 85
  • 133

2 Answers2

10

As far as I understand from the reverse documentation, reverse works on arrays, and so it should use @_ rather than the scalar $_?

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

$_ = "dlrow ,olleH";
print reverse;                              # No output, list context
print scalar reverse;                       # Hello, world
benui
  • 6,440
  • 5
  • 34
  • 49
4

Whatever is in the official documentation is the Perl specification. If Perl does what the docs say it should do, then it is not a bug. It is a language design and implementation decision.

mob
  • 117,087
  • 18
  • 149
  • 283