in reply to Populating scalar using more than 2 while loops.
In your inner while loops, $dataset = $1; is overwriting the contents of $dataset on every match. Personally, instead of appending the matches to a string, I would have split the matches directly inside the inner while, and then pushed the individual words onto an array or stored them in a hash directly. But in this code, one quick fix is to do $dataset .= " $1 "; inside the loop instead, so that the matches are appended to the string rather than replacing it. Also, note that in your second example, three of the inner while loops can be combined:
while ( $mycorpus{$filename} =~ /(?:title|text|comment):#(.*?)#/g ) { $dataset .= " $1 "; }
It's good you're using Data::Dumper, I would recommend to insert more print statements to debug issues like this - one in every loop of your code would give a hint as to what's going on.
(BTW, in general, please omit code that isn't relevant to the question, in this case that's both sub getCorpus definitions, and run your code through perltidy.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Populating scalar using more than 2 while loops.
by Maire (Scribe) on Aug 26, 2018 at 07:39 UTC |