Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

G'day Marshall,

I added strict and warnings: both missing from your code. I also show assignments to %master_letter_freq and @result: also missing from your code. The remainder is a verbatim copy of the code you posted.

#!/usr/bin/env perl use strict; use warnings; my %master_letter_freq = qw{w 1 h 1 t 1 o 1 r 2 e 1}; my @result = qw{thew trow whew}; RESULT: foreach (@result) { my %seen; $seen{$_}++ for (split //,lc $_); foreach (keys %seen) { next RESULT if ($seen{$_} > $master_letter_freq{$_}); } print "$_\n"; } foreach (@result) { my %seen; $seen{$_}++ for (split //,lc $_); my $no_print = 0; foreach (keys %seen) { $no_print++ if ($seen{$_} > $master_letter_freq{$_}); } print "$_\n" unless $no_print; }

Here's the output:

thew trow thew trow

Please run that code, exactly as is, and report the output.

If you still see "whew" in the output, then there's potentially a bug in Perl. I'm using 5.32.0. What are you using? Post an SSCCE so we can investigate.

If you don't see "whew" in the output, then either the code you're running is not the code you posted, or there's something else going on in the code before this that you haven't shown.

Add code to query every variable before and/or after it changes. For instance, with Data::Dump:

dd \%master_letter_freq; # <-- QUERY dd \@result; # <-- QUERY RESULT: foreach (@result) { print "|$_|\n"; # <-- QUERY my %seen; $seen{$_}++ for (split //,lc $_); dd \%seen; # <-- QUERY # ... and so on ...

Note the pipe characters (|$_|) that may help to identify whitespace or control characters that aren't readily visible.

If that doesn't help, try (platform-dependent):

./script.pl | cat -vet

That's something of a last resort, but it may show up something if all else has failed to identify the problem.

— Ken


In reply to Re: Next from inner loop only works "most of the time" by kcott
in thread Next from inner loop only works "most of the time" by Marshall

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 lurking in the Monastery: (5)
As of 2024-04-19 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found