in reply to Re: please reply
in thread please reply
wanted to know why while loop is ended after splitting and why found is used
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: please reply
by ww (Archbishop) on Jan 06, 2013 at 20:50 UTC | |
However, when I run your code, supplying a test file (multi-char strings, some of which satisfy either of two contradictory definitions of bigrams* and some non-bigram strings such as nobigram, each separated by 2 newlines), your code returns " : 1" for pairs of words -- each concatenated with the following word (except in the case of "nobigram" which is first concatenated with the preceding word and then with the following word).
I cannot reproduce your "loop is ended after splitting EXCEPT (and then not perfectly) by removing the doubled curly braces at Lns 9-10 and 22-23, in which case only a single instance of the final two words of sample data are returned (along with the " : 1"). (Update: That's not a correct count for either definition cited for a bigram) As to "why found is used," it seems possible, in the overly limited context you've provided, that it's intended to be a counter -- a variable in which to stash the number of bigrams found. I realize that seems exessivly obvious, but, IMO, it's the only obvious possible-answer. In any case, if counting is your intent, please see http://search.cpan.org/~emorgan/Lingua-EN-Bigram-0.01/lib/Lingua/EN/Bigram.pm (or some fork for the language in which your interests lie). *Definitions vary:
For clarity, here is the content (verbatim) of the text file:
| [reply] [d/l] [select] |
|
Re^3: please reply
by CountZero (Bishop) on Jan 06, 2013 at 19:07 UTC | |
It runs, but it seems not to output anything meaningful, so it is very well possible it's logic is wrong. CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James My blog: Imperial Deltronics | [reply] |
|
Re^3: please reply
by Anonymous Monk on Jan 06, 2013 at 23:14 UTC | |
wanted to know why while loop is ended after splitting and why found is used :) Curious, because this isn't what you asked for :) :) but you can find out by understanding what each part of the program does, and inserting print/Data::Dumper parts at various points in the program If you limit the input while Dumper-ing it should be easier to follow | [reply] |