Hello all..Im working on a cgi script am trying to compare 2 data files, but i have to have them as Array reference of hash references so i can pass the results on to an html template. Im still working on the code, i just thought i'll get another insight. Thanks in advance i have updated the code, but now i am getting an "Use of uninitialized value in string eq"

my code

#!/usr/bin/perl -w use strict; use CGI; use HTML::Template; my $cgi = new CGI; my $tmpl = HTML::Template->new (filename => 'tmpl/annotation.tmpl'); print "Content-type: text/html\n\n"; my $offgenes = 0; my $prodgenes = 0; my @offcordinates; my @prodcordinates; my $exactmatching = 0; my $start; my $stop; my $start1; my $stop1; my $threeprimematch; my %findgene; my %findgene2; my @officialannotation = (); my @prodigalannotation = (); my $hash_ref; my $hash_ref2; open(INFILE, "<", "genbankfile.txt") or die "cannot open file $!"; while(<INFILE>) { if ($_ =~ /\d+/) { $offgenes++; } @offcordinates = split; $findgene = { "start" => $offcordinates[1], "stop" => $offcordinates +[0] }; push @officialannotation, $findgene; } open(INFILE2, "<", "prodigalAnnotation.txt") or die "cannot open file +$!"; while(<INFILE2>) { if($_ =~ /\d+/) { $prodgenes++; } @prodcordinates = split; $findgene2 = { "start1" => $prodcordinates[0], "stop1" => $prodco +rdinates[1] }; push @prodigalannotation, $findgene2; } foreach $genes ( @officialannotation ) { my %genes_= %$genes; foreach $genes2 ( @prodigalannotation ) { my %genes2 = %$genes2; if($genes{start} eq $genes2{start1}) { $exactmatching++; } } } print "$offgenes\n"; print "$prodgenes\n"; print "$exactmatching\n"; close(INFILE); close(INFILE2);

Data file 1 data file 2

start stop start stop

1234 5678 1234 5678

2123 1234 3233 2123

I am trying to loop though to compare the data in file 1 to file 2.

for example if 1234 and 5678 is seen in the start and stop column in file 1 and seen in file 2, count that line.

Also, if 2123 is seen is the start column and not seen in the start of the second file 1. count that also. This is my biggest problem at the moment. help


In reply to looping through an array reference of hash reference by PrincePerl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.