in reply to Re: underline variable width column headings
in thread underline variable width column headings
I could get the underline I want, but the headers no longer lined up with the letter above it’s corresponding letter in the columns. The columns print as they should with three spaces between them. That is my problem, can anyone help? Should anyone want to run the codecolored(scalar @{$trigraphs{$k}}, 'underline'), and colored(scalar keys %{$flanks{$k}}, 'underline')); Note: the last ) is to match the ( in sprintf().
#! /usr/bin/perl use strict; use warnings; use Term::ANSIColor; # get cipherText my $txt = do{local $/; <DATA>}; $txt =~ s/\s//go; my @letters = split '', $txt; # create trigraphs my (%trigraphs, %flanks); add_trigraph('-', @letters[0..1]); while(@letters > 2){ add_trigraph(@letters[0..2]); shift @letters; } add_trigraph(@letters[0..1], '-'); # sort by most seen middle character my @sorted_keys = sort{ @{$trigraphs{$b}} <=> @{$trigraphs{$a}} || $a cmp $b } keys %trigraphs; # create columns/lines for(my $i = -1;$i < @{$trigraphs{$sorted_keys[0]}};++$i){ my @line; for my $k (@sorted_keys){ unless($i > -1){ # create header @{$trigraphs{$k}} = sort @{$trigraphs{$k}}; push @line, sprintf('%2d%s%-2d', scalar @{$tri +graphs{$k}}, $k, scalar keys %{$flanks{$k}}); next; } next unless defined $trigraphs{$k}->[$i]; push @line, sprintf(' %s ', $trigraphs{$k}->[$i]); } print "@line\n"; } sub add_trigraph { ++$flanks{$_[1]}->{$_} for @_[0,2]; push(@{$trigraphs{$_[1]}}, join('', @_)); } __DATA__ # elcy pg.73 in P format FDRJN UHVXX URDMD SKVSO PJRKZ DYFZJ XGSRR VTQYR WDARW DFVRK VDRKV TDFSZ ZDYFR DNNVO VTSXS AWVZR
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: underline variable width column headings
by quester (Vicar) on Dec 15, 2006 at 07:28 UTC | |
by wlegrand (Initiate) on Dec 17, 2006 at 04:10 UTC | |
by quester (Vicar) on Dec 18, 2006 at 09:08 UTC | |
by wlegrand (Initiate) on Dec 19, 2006 at 01:51 UTC |