in reply to Swapping Two Hash Values

The simplest way I know to swap values for hash keys is with a slice: @hash{ 'foo', 'bar' } = @hash{ 'bar', 'foo'};

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Swapping Two Hash Values
by sauoq (Abbot) on May 28, 2003 at 00:53 UTC
    The simplest way I know to swap values for hash keys is with a slice:

    That's what he tried to do. He just got the syntax wrong.

    Cody, instead of

    $hash{$item,($item -1)} = $hash{ ($item -1), $item};
    try
    @hash{$item, ($item - 1)} = @hash{($item - 1), $item};
    Pay careful attention to the sigils. You have to use an @ to specify a slice.

    -sauoq
    "My two cents aren't worth a dime.";