How can I swap two Perl variables without using the third?

后端 未结 7 923
盖世英雄少女心
盖世英雄少女心 2021-01-17 13:27

I want to swap two variables values without using the third variable in Perl, e. g.:

my $first = 10;
my $second = 20;

Please suggest me how

相关标签:
7条回答
  • 2021-01-17 13:53

    You can write:

    ($first, $second) = ($second, $first);
    

    (See §3.4 "List Assignment" in Learning Perl, Third Edition.)

    0 讨论(0)
提交回复
热议问题