in reply to retrieving in the correct order

or, if the first array is really a text file, say on a UNIX/LINUX system, you could cat the first file and read it line by line.. no?
the scanning perl program gen.pl: --------------------------------- #!/usr/bin/perl use strict; my @array = qw(13470319 13470331 15460001 13490216); my @array2; while(my $line = <> ) { foreach my $id (0..$#array) { $array2[$id]=$line if $line =~ m/^gi\|($array[$id])\|/; } } print "order: ", join (" ", @array), "\n"; map {print} @array2; ------------------------------- the text file: gi|13470331|ref|NP_101896.1| hypothetical protein MFWVTKKALMPFLMLPAGIIFVSAVGYAINWLFSTLFQFQPPLVEGPAGPVTVLIFTITMLLAYDISYYL gi|13470319|ref|NP_101897.1| hypothetical protein MGAYCQAHPACKVTDRTVIGRRDAAMNAPFVLAIPRTRTFEVVTSAARLAEIAPAWTALWQRAGGLVFQH ------------------------------- the execution: # cat gen.txt | perl gen.pl order: 13470319 13470331 15460001 13490216 gi|13470319|ref|NP_101897.1| hypothetical protein gi|13470331|ref|NP_101896.1| hypothetical protein

this just looked like a quick and keep it simple job to me..

UPDATE: updated the code to display correct order..

--
to ask a question is a moment of shame
to remain ignorant is a lifelong shame

Replies are listed 'Best First'.
Re^2: retrieving in the correct order
by Animator (Hermit) on Dec 16, 2004 at 21:02 UTC

    I think you are missing the point...

    If I understand the poster correctly then he (or she) wants to output them in the order they appear in the second array, so in this case first line/element 13470319, after that line/element 13470331 and so on

      aah.. oops.. indeed i understood wrongly.

      update: and wisdom came to me :-D check the above code... simple, line by line and in the correct order. this time i tested the code ;-)

      --
      to ask a question is a moment of shame
      to remain ignorant is a lifelong shame