Hi Monks, So I have two .txt files
File 1 Start Stop Name 234 388 abc 458 267 pqr ... ... 873 490 xyz
File 2 Name abc dfr hyt hig wer pqr ... ... xyz
What I have done is read the file 2 names and if they occur in file 1 then get an output for those names with their respective start and stops. For eg: abc and pqr of file 2 occur in file 1 hence,
Output file 234 388 abc 458 267 pqr
What my problem is that the last entry which is 873     490    xyz should appear as the last entry in my output file but it isn't. I get all the others but the last entry isn't showing up on my output file. Any idea as to why this must be happening? Here is my code:
#!/usr/bin/perl # Open info file, and read in all the name start and stops my $input_file = "/Users/myfolder/inputfile.txt"; die "Cannot open $input_file\n" unless (open(IN, $input_file)); my %name_and_Start_Stop; while (chomp($line = <IN>)) { my (@columns) = split /\s+/, $line; my $name = $columns[3]; my $Start = $columns[1]; my $Stop = $columns[2]; $name_and_Start{$name} = $Start; $name_and_Stop{$name} = $Stop; } close(IN); # Open the input file, and read each name die "name_list.txt" unless open(IN, "name_list.txt"); #Open output file and write the name start and stops die "output.txt" unless(open(OUT,"> output.txt")); while (chomp($symbol = <IN>)) { my $Start = $name_and_Start{$name}; my $Stop = $name_and_Stop{$name}; print OUT "$Start\ $Stop \ $name \n"; } close(OUT); close(IN);
Why isn't it outputting the last name xyz? Is it something in the split function?

In reply to perl leaving out the last value? by perllearner007

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.