如何在不使用第三个的情况下交换两个 Perl 变量? [英] How can I swap two Perl variables without using the third?
本文介绍了如何在不使用第三个的情况下交换两个 Perl 变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在不使用 Perl 中的第三个变量的情况下交换两个变量值,例如.:
I want to swap two variables values without using the third variable in Perl, e. g.:
my $first = 10;
my $second = 20;
请建议我如何以简单的方式在 Perl 中做到这一点.
Please suggest me how we can do this in Perl in a simple way.
推荐答案
最好的办法就是只提供给我们这样一行就可以交换值:
The best way that only provide us is like this in one line you can swap the values:
($first, $second) = ($second, $first);
这篇关于如何在不使用第三个的情况下交换两个 Perl 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文