+2  A: 

There is a general pattern here, and it is this: this is a set intersection problem, and as such can be solved easily with Perl "sets", which we tend to call hashes :).

The approach is to create a set out of one of your data files (ie. indexing it into a hash table, like so: %set = (a => 1, b => 1, c => 1), where the actual value is immaterial, since we're going to be testing it with the "set membership operator" exists).

Once you have that, it is a simple matter of going through the other data set, and test membership of one of its keys (in your case, source IDs) in the %set above.

So, assuming the channel map file is in the following format:

ID,NAME

and the source ID file is just one ID per line, the you could do the following:

open my $CHANNEL_MAP, q{<}, $channel_map_file_name or die $!;
my %channel_map
    = map {
        chomp;
        my @mapping = split /,/;
        $mapping[0] => $mapping[1] # not needed, just being explicit.
      } <$CHANNEL_MAP>;
close $CHANNEL_MAP or die $!;

# source ID file passed as a command line argument
while (<>) {
    chomp;
    print "$_ = $channel_map{$_}\n"
        if exists $channel_map{$_};
}

However, this seems a bit pointless, since all you seem to want to do is to filter the channel map file by the existing source IDs. In that case, you could simply index the source ID file instead (use the technique above), and then simply go through the channel mappings file and print each line for which the ID exists in your source IDs.

Pedro Silva
Thanks so much for the help! This has definitely got me on the right track and will also help me understand perl a bit more.
fsck3r
A: 

It's all rather fuzzy since you're not clear on the formats of your files.

But, assuming you have a file called names.txt that lists the name in the "15431 = MyTV8" format, one per line, and you have the other file while lists only numbers, you could use something like this:

#!/usr/bin/perl

open NAMES, '< names.txt' or die $@;
my %names = map { /(\d+) = (.+)/; ($1, $2) } (<NAMES>);

while (<>)
{
   chomp;
   if (exists $names{$_}) {
      print "$_ = $names{$_}\n";
   } else {
      print "$_\n";
   }
}
Boone