Implementing Swap [was Re: [] Report on Yesterday's Meeting]

Mikhael Goikhman migo at
Sun Jun 5 11:22:15 PDT 2005

On 05 Jun 2005 20:04:50 +0300, Shlomi Fish wrote:
> In the meeting, Shlomo used a swap($a, $b) function. Some people claimed it 
> could not be implemented in Perl, or only by using prototypes. But in fact it 
> can:

This implementation explains the technique better:

    sub swap { ($_[0], $_[1]) = ($_[1], $_[0]) }

>From what I can find on internet, it seems this should work in perl4 too.

Another way to implement swap (without assigning to @_ elements) is:

    sub swap (\$\$) {
        my ($a, $b) = @_;
        ($$a, $$b) = ($$b, $$a);

And sometimes it is more readable to just write ($a, $b) = ($b, $a);
inline, instead of calling function swap($a, $b).

> Another thing that MiGo claimed was that Internet Explorer did not support 
> accesskey="". However, it can do just that.

I have no MS Windows to claim this. But I know that my presentations
(at least some) use accesskey="N", and Alt-N didn't work on YAPC.
I don't remember whether it was Konqueror or Opera or IE, however. :)


perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'

More information about the Perl mailing list