Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Some Basic Help.

by invaderzard (Acolyte)
on Sep 25, 2012 at 07:14 UTC ( #995500=note: print w/ replies, xml ) Need Help??


in reply to Re: Some Basic Help.
in thread Some Basic Help.

What can you tell me about hashes? Thanks.


Comment on Re^2: Some Basic Help.
Re^3: Some Basic Help.
by Jenda (Abbot) on Sep 25, 2012 at 08:06 UTC

    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.

    Jenda
    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?

        First by reading some docs. Random typing will not work!

        What's the $lol variable for? Why do you select() a filehandle opened for reading? What do you think will be in $_ on line 7? You declare array @train, but later on attempt to use hash %train!

        Jenda
        Enoch was right!
        Enjoy the last years of Rome.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2015-07-07 11:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls