Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
A few more suggestions for you...
This code.... # First, get the subset cluster number. our ($cluster1, $other1) = split(/\s/, $line2, 2); chomp $other1; my @A2 = split(/\s/, $other1); chomp @A2; is just this... my ($cluster1, @A2) = split(/\s+/,$line2); This line does not do what you think it does... chomp $c; # remove trailing white space in $c ('ugly stuff')
Probably everywhere you split on \s, \s+ is what you need. This removes any sequence of space characters. Space characters are: the space,\t\f\r\n. So when you split on white spaces, there is no need to chomp. BTW, chomp does not remove trailing white space, only the trailing \n if present. There will not be any trailing \n or any other white space if you split on \s+.

There is no need to do the split in two phases. In my line above, $other gets the first token and @A2 get all of the rest.

An "our" variable is used to give a variable package scope and also causes it to be put in the symbol table for export. If you really mean to share a variable between two functions, declare a "my" variable at a higher level that is common to both. There is no need in your code for any "our" variables. It would help if you give better names to the variables.

You are very close to having this work under "use strict; use warnings;". Go ahead and include those directives.

Update: re: performance...I don't know enough about your application (like what input lines look like) and what the definition of "equivalent files" means to say anything other than some generic advice. Code like the below, will cause a*A2 comparisons. If these 2 arrays are big, then that's a lot of compares. Use the profiler to see if this is a bottleneck or not. A hash based approach might work out well. Do a search for "compare arrays". But don't spend time on it if this is not where the problem lies.

foreach $i(@a){ foreach my $i2(@A2){ if($i =~ m/$i2/){

In reply to Re: file comparisons: - making it faster by Marshall
in thread file comparisons: - making it faster by $new_guy

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 surveying the Monastery: (4)
As of 2024-03-29 11:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found