Unless the words array is also needed for something else, my preferred solution would be to skip it entirely and just use a regex on the whole file content (what can I say, I like regexes):
use File::Slurp;
my $text = read_file('input.txt');
while ($text =~ /" (.*?) "/sg) {
print "Found quoted string with ".split(' ', $1)." words: $1\n";
}
The regex might need to be adjusted depending on the exact definition of what should be counted as a quoted string within the input data.
-
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.
|