Hi,
I have searched for a way to underline text on your board and came up with "How do I print characters with underline or bold?" #106173=categorized question:
It doesn’t help me for what I want to do, because I am using Perl, version 5.005_01 built for powerpc-machten (BSD 4.4) and I cant use modules.
I can’t use MacPerl because I use several switches on the command line when I run the complete program.
I’m not a student and this isn’t a homework assignment.
I want to underline only the column headings and not the spaces between, that I get from the output of this portion of the program.
The underlining varies; as much as 5 in the case of high frequency letters such as 11R13 to 3 for low frequency letters like 5F7.
I have been trying "\137" on line 29 which should show as:
push @line, sprintf('%2d%s%-2d', scalar @{$trigraphs{$k}}, $k, scalar keys %{$flanks{$k}});
and I can’t get it right. Perhaps my approach is wrong. Thanks for any help.
#! /usr/bin/perl -w
use strict;
# 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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.