Skip to content

Instantly share code, notes, and snippets.

@hakobe
Created August 14, 2014 14:34
Show Gist options
  • Save hakobe/55231183fdb0fab2d6ae to your computer and use it in GitHub Desktop.
Save hakobe/55231183fdb0fab2d6ae to your computer and use it in GitHub Desktop.
"Perl5.20のKey/Value Hash Slice" + "リストをスカラコンテキストで評価するとリストの最後の値になる" が組み合わさった様子
use strict;
use warnings;
use utf8;
use v5.20.0;
my $h = {
hoge => 'hoo',
fuga => 'foo',
};
my $v1 = %{$h}{hoge};
warn $v1; # => hoo
my $v2 = %{$h}{'hoge', 'fuga'};
warn $v2; # => foo
@hakobe
Copy link
Author

hakobe commented Aug 14, 2014

HashのリファレンスになってるところをHashに変えると以下の様な警告が出る。(逆に上のような例だと警告でない)

%h{"hoge"} in scalar context better written as $h{"hoge"} at hoge.pl line 11.
%h{...} in scalar context better written as $h{...} at hoge.pl line 14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment