Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Some Basic Help.

by Jenda (Abbot)
on Sep 24, 2012 at 09:01 UTC ( #995318=note: print w/ replies, xml ) Need Help??

in reply to Some Basic Help.

while (my $train = <trained>) { while (my $predict = <predict>) { ... } seek predict, 0, 0; // need to return to the start of the predict fil +e!!! }

Also, the condition is wrong! It should be if ($train == $predict) if you want to compare numbers or if ($train eq $predict) if you want to compare strings. Perl is happy to convert values from one form to the other, but you have to tell it which one you want. Also in case the files contained floating point numbers the comparison using == would most probably not "work". The two numbers would have to be absolutely equal which is (also due to limited precision computation) very unlikely. You will want to test whether they are within a certain range from each other instead.

You may also want to consider reading the files just once. Choose the smaller one, read it into an array or hash (as you seem to want to test for equality a hash would work better) and then read the other file and check whether the value is present in the array/hash.

Enoch was right!
Enjoy the last years of Rome.

Comment on Re: Some Basic Help.
Select or Download Code
Re^2: Some Basic Help.
by invaderzard (Acolyte) on Sep 25, 2012 at 07:14 UTC
    What can you tell me about hashes? Thanks.

      Here's a quick intro.

      In your case you would not have any values in the hash, just keys. You'd read the smaller file and add the lines to a hash as keys (the values are irrelevant, use 1 for example). Then as you would read the other file you'd just check whether exists $hash{$line} and you'd know right away whether such line was in the first file or not.

      Enoch was right!
      Enjoy the last years of Rome.

        How do I then, get the data i want into the array?
        use Modern::Perl open trained , 'D://ARP//libsvm-3.12//families//antioxidant//independe +nt.scale'; open predict , 'D://ARP//libsvm-3.12//families//antioxidant//testing.s +cale'; my $counter = 0; my $lol = 0; select trained; my @train = $_; while (<predict>) { #print $_; my $predict = $_; if (exists $train{$predict} { print $predict; $counter = $counter + 1 } } print $counter;

        like this?

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2014-12-29 00:39 GMT
Find Nodes?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?

    Results (183 votes), past polls