in reply to Re^2: Opinion: where Perl5 wasn't attractive for me
in thread Opinion: where Perl5 wasn't attractive for me

I can't imagine many cases at all where you might want to use length $_ as an index or key, but almost every case where you would want to be able to type a key without having quotes all over the place.

The simplest way to do what you want is with a leading unary + to make it not be a bareword.

use strict; use warnings; use Data::Dumper; my %foo; $foo{+length} = 42; $foo{length} = 'interminable'; print Dumper \%foo;
Gives:
Use of uninitialized value $_ in hash element at test.pl line 5. $VAR1 = { '' => 42, 'length' => 'interminable' };

Replies are listed 'Best First'.
Re^4: Opinion: where Perl5 wasn't attractive for me
by rsFalse (Chaplain) on Nov 19, 2014 at 15:12 UTC
    Ok. Thats true. And I used $hash{(length)}++ to save occurences of the substring lengths.
    And this works too: $foo{- -length} = 42;, but '+' of course is better.