# Write a function to precompute all those boolean keys you want to # sort by. This should be an improvement because now the code has # each condition only once, not twice, so we reduced code duplication. # The key is just a string of "0" and "1" characters. For simplicity, # we store the key right into the record. our @networks = qw(ABC CBS FOX NBC SyFy TNT USA); our $network_string = join('|',@networks); sub show_sortflags { my($s) = @_; my @k; push @k, ( !($s->{user} =~ /LadyAleena_($network_string|TV)/ && $s->{name} !~ /TV/), !($s->{user} =~ /LadyAleena_($network_string)/ && $s->{name} =~ /TV shows$/), !($s->{user} eq 'LadyAleena_TV' && $s->{name} eq 'Premium TV shows'), !($s->{user} eq 'LadyAleena_TV' && $s->{name} eq 'TV shows'), !($s->{user} eq 'LadyAleena_TV' && $s->{name} eq 'TV networks'), !($s->{user} eq 'Lady_Aleena' && $s->{name} =~ /(Comedians|Musicians)/), !($s->{user} eq 'Lady_Aleena' && $s->{name} =~ /(Horror|Science fiction)/), !($s->{user} eq 'Lady_Aleena' && $s->{name} eq 'Ripley\'s & Guinness'), !($s->{user} eq 'LadyAleena_home'), !($s->{user} eq 'Lady_Aleena' && $s->{name} =~ /(Followers' businesses|List subscribers)/), ); my $k = join "", map { $_ ? "1" : "0" } @k; $$s{sortflag} = $k; } for my $s (@showtab) { show_sortflags($s); }