in reply to Re: Interchanging hash values (List::Util)
in thread Interchanging hash values
Why make two passes?
D:\Perl\test>perl use strict; use warnings; my %h; @h{'a'..'j'} = 0..9; print %h, $/; my ($min,$max) = (keys %h); ($min,$max) = ( $h{$min} < $h{$_} ? $min : $_, $h{$max} > $h{$_} ? $ma +x : $_ ) for keys %h; @h{$min,$max} = @h{$max,$min}; print %h, $/; ^Z a0b1c2d3e4f5g6h7i8j9 a9b1c2d3e4f5g6h7i8j0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Interchanging hash values (single pass - or not)
by Aristotle (Chancellor) on Apr 21, 2003 at 11:39 UTC |