File 1 Start Stop Name 234 388 abc 458 267 pqr ... ... 873 490 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,File 2 Name abc dfr hyt hig wer pqr ... ... xyz
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:Output file 234 388 abc 458 267 pqr
Why isn't it outputting the last name xyz? Is it something in the split function?#!/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);
In reply to perl leaving out the last value? by perllearner007
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |