Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

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

G'day corfuitl,

Welcome to the monastery.

As ww points out (above), if you don't tell us what the problem is, we're not in much of a position to advise how to fix whatever that problem might be. Read the guidelines in "How do I post a question effectively?" to find out how to get better answers. When you understand that, "How do I change/delete my post?" explains how to add the additional information to your original post.

Having said that, there are some basic problems with your code which you should address immediately. This exercise may fix whatever your problem is. Even if it doesn't, it'll certainly provide better information for us to help you.

  • Add use strict; and use warnings; near the start of your script. See strict and warnings. I strongly recommend you do this with all your scripts.
  • If you don't understand the output from strict or warnings, add use diagnostics; for more detailed messages. I'd recommend removing (or, at least, commenting out) this line in your production code. See diagnostics.
  • Consider adding use autodie; to your scripts. It saves having to hand-craft all the "... or die "Some specific message: $!";" pieces of code; it also means that you don't need to check that you haven't accidently omitted such code. See autodie.
  • Take a look at the documentation for open. Lexical filehandles are generally a better choice than package variables.
  • Use meaningful variable names. @mt and @tm mean nothing to me; their meaning may well elude you when you revisit this code in six months or so for upgrade or maintenance work. Each is converted to the other by a simple swapping of their two characters: this makes your code highly error prone. The same comments apply for $lm and any similarly meaningless names you may have elsewhere.
  • You've coded "my $i, $j;". This is wrong three times over:
    1. It is syntactically wrong: see my.
    2. It's also wrong because, while it looks like you're attempting to declare $j, that's not a variable you use in your script: you either meant $k here, or $j further down your code.
    3. Assuming you're attempting to declare these variables for use in the for loops, that's not the way to do it.

      The reasons why are somewhat subtle and are explained in perlsyn: Foreach Loops: the typical gotcha occurs because values assigned to those variables within the loop are not visible outside the loop; the value of the variable will be the same before and after the loop regardless of how it might have been modified within the loop.

      Don't worry if that's confusing or seems rather heavy going. Just declare your loop variables when you code your loop, like so:

      for my $i (...) { # $i available (and localised to) here }

      and for nested loops

      for my $i (...) { # $i available (and localised to) here for my $j (...) { # The same $i available here # $j available (and localised to) here for my $k (...) { # The same $i and $j available here # $k available (and localised to) here } } }
  • Finally, you're missing a closing brace ('}') at the end of your posted script.

-- Ken


In reply to Re: find the max fuzzy matching - perl by kcott
in thread find the max fuzzy matching - perl by corfuitl

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 meditating upon the Monastery: (3)
As of 2024-04-26 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found