in reply to Matching elements in two arrays and printing the element next to the match.

You don't do any error checking and you don't use warnings which would allow Perl to alert you of unopened files. When opening files, use the following:

... open (FILE1,$p) or die "Couldn't open file '$p': $!"; ...

Also, your approach will be very (very) slow, because for each entry in the first file you will go through all lines of the second file. It will likely be better to store the entries from the smaller file in a hash and then go through the larger file once and compare the entries to it.

  • Comment on Re: Matching elements in two arrays and printing the element next to the match.
  • Download Code

Replies are listed 'Best First'.
Re^2: Matching elements in two arrays and printing the element next to the match.
by 7stud (Deacon) on Mar 22, 2010 at 11:52 UTC

    Barewords for file handles? Two arg form of open()? How about some modern perl:

    open my $ID_FILE, '<', 'ids.txt' or die "Couldn't open ids.txt: $!";
      You forgot the smiley