If I understand the documentation correctly, reverse usually works with lists. In the context of a list used without arguments, it returns an empty list and by default does not assign it anywhere. In your example, let's say it displays unchanged $_ ;
Forcing reverse into a scalar context changes its behavior and makes it back to character strings and uses $_ by default. Since say can be used to print lists, as well as for scalars, it does not force its arguments in a scalar context.
Perl probably does DWIM only for the given "I" values.
A breakdown of what the converse does when:
#!/usr/bin/env perl use strict; use v5.12; my $inscalar = "foo bar"; # `reverse` is in list context, $in is coerced to a single-element list my @outlist = reverse $inscalar; # `reverse` is in scalar context, so it reverses strings my $outscalar = reverse $inscalar; say join(" | ", @outlist); # prints "foo bar" say $outscalar; # prints "rab oof" # the "normal" behaviour of `reverse` my @inlist = qw(foo bar); @outlist = reverse @inlist; say join(" | ", @outlist); # prints "bar | foo"
source share