Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: find the max fuzzy matching - perl

by kcott (Archbishop)
on Oct 26, 2013 at 05:48 UTC ( [id://1059793]=note: print w/replies, xml ) Need Help??


in reply to find the max fuzzy matching - perl

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1059793]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-16 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found