Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
And here you go. I &heart programming excercises like this. Reads files, outputs a reverse sorted list based on # of occurences. Note that some trigraphs may not be totally valid because of the s/\W//g;. for example, "this is a line.This is another one" will yield "lineThis" as a word to be trigraphed. This is trivial to fix, though :)

Update yes, it was.
I changed
s/ //g;
to s/\W//g; thanks, Albannach! (wave)

# # # use strict; my %symbol; my %tri; my @trikeys; my $line; my $ctr; print "Processing file...\n"; while ($line = <>) { for (split /\W/,$line) { #discard all non-alpha. be *greedy* s/\W//g; (length($_)>2) && $symbol{lc($_)}++; } } print "Collecting trigraphs...\n"; foreach (keys %symbol){ for ($ctr=0; $ctr <= (length($_)-3);$ctr++) { $tri{lc(substr ($_,$ctr,3))}+= $symbol{$_}; } } @trikeys = sort {$tri{$b} <=> $tri{$a}} keys %tri; print "Total Trigraphs : ",$#trikeys,"\n"; print "Trigraph\tCount\n"; foreach (@trikeys) { print "$_\t$tri{$_}\n"; }

In reply to Re: Re: Letter frequencies by boo_radley
in thread Letter frequencies by Leitchn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-20 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found