Thanks Cristoforo,

I modified the code as suggested by you but I thing the program is giving me error of uninitialized values.

#!/usr/bin/perl -w + use strict; use warnings; my $matchfile = "match_super.dat"; my $ctfile = "M23263_rna_300-1.dat_1.ct"; my @match;my %data;my $fragment; my $pos; open (A, "<", $matchfile) or die "Check the file $!\n"; while (my $line = <A>) { chomp $line; (undef, $fragment, undef, $pos) = split(/\t/, $line); $data{$pos} = $fragment; } close (A); my ($num1, $base, $num2, $num3, $connect, $num4); open (B, "<", $ctfile) or die "Check the file $!\n"; while (my $ctline = <B>) { chomp $ctline; if ($ctline =~ /^(\d+\s+dG.*)/) { # print "$1\n"; next; + next; } $pos = (split /\s+/)[0]; print "$data{$pos} $pos\n" if $data{$pos}; } close (B);
Error: Use of uninitialized value $pos in hash element at ./second_str_map.pl + line 29, <B> line 298. Use of uninitialized value $_ in split at ./second_str_map.pl line 28, + <B> line 299. Use of uninitialized value $pos in hash element at ./second_str_map.pl + line 29, <B> line 299. Use of uninitialized value $_ in split at ./second_str_map.pl line 28, + <B> line 300. Use of uninitialized value $pos in hash element at ./second_str_map.pl + line 29, <B> line 300. Use of uninitialized value $_ in split at ./second_str_map.pl line 28, + <B> line 301. Use of uninitialized value $pos in hash element at ./second_str_map.pl + line 29, <B> line 301.

In reply to Re^6: Key value pair in hash inside while loop by newtoperlprog
in thread Key value pair in hash inside while loop by newtoperlprog

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.