How can I represent sets in Perl?

后端 未结 3 804
闹比i
闹比i 2020-12-05 13:09

I would like to represent a set in Perl. What I usually do is using a hash with some dummy value, e.g.:

my %hash=();
$hash{\"element1\"}=1;
$hash{\"element5\         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 13:26

    That's how I've always done it. I would tend to use exists rather than defined but they should both work in this context.

提交回复
热议问题