in reply to Tied Variables - why?
Now I could subcass CGI and muck around with popup_menu or I could write yet another CGI module but why when I can coax CGI.pm into DWIM with in 10 lines of code? My favorite uses usually are coaxing some new behavior out of existing code. Paging/Filtering filehandles.. etc.# Kludge to get options sorted. package MySortHash; use Tie::Hash; use vars qw(@ISA); @ISA = qw( Tie::StdHash ); sub FIRSTKEY { my $self = shift; @{ $self->{VERY_UNLIKELY_HASH_KEY} } = sort {$self->{$a} cmp $self +->{$b} } grep { $_ ne 'VERY_UNLIKELY_HASH_KEY' } keys %{$self}; return shift @{ $self->{VERY_UNLIKELY_HASH_KEY} }; } sub NEXTKEY { my $self = shift; return shift @{ $self->{VERY_UNLIKELY_HASH_K +EY} }; } # later in package main... tie %thash, 'MySortHash' ; # tied hash with sorted keys... print $q->popup_menu(-name=>$p , labels=> \%thash, -values=> [ (keys % +thash) ] );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Tied Variables - why?
by Aristotle (Chancellor) on Sep 07, 2002 at 11:15 UTC | |
by shotgunefx (Parson) on Sep 07, 2002 at 22:36 UTC | |
by Aristotle (Chancellor) on Sep 07, 2002 at 23:08 UTC | |
by shotgunefx (Parson) on Sep 07, 2002 at 23:15 UTC |