Perl - help needed

Hi all,

I'm a rookie in Perl scripting, and I have a task to do.

Generally it's something like that:

I have a reference file consisting of a number and name, tab-separated. One entry in one line, about 99 lines in file.
The other file is an XML log file, where in one specific branch, eg. <id> there's a number.
All I have to do, is to (I guess) get the first file into hash array and compare it to the XML. If script finds the number, it displays it's name from array.

But.. How to do it? Can anyone help me, please?
A piece of code, clues or something?

Thanks in advance,
rgds!

If you post a sample of your input and an example of the desired output it will be much easier.

Sample input and output?

Well there are two files:
first:

001 name001
002 name002
003 name003

The second file, XML:

<main>
<some_data>
<id>001</id>
</some_data>
</main>

and the script, when finds xml's <id> field should write proper value, like "name001" for id=001. When <id> is not listed in first reference file, some error msg should occur. The output should be on-screen only, no need to write to new file.

The script is for log testing purposes.

OK,
could you post an example of the desired output?
Should it be in xml format?

The desired output? No, there's no need to create any output file, only thing the srcipt should do is to write something, like:

Found id: 001. Test result: name001

If AWK is acceptable:

awk 'NR == FNR { 
  _[$1] = $2
  next
  }
NF > 1 { 
  printf "Found id: %s. Test result: %s\n",
  $2, _[$2] ? _[$2] : "N/A"
}' first FS='<id>|</id>' xml

Use nawk or /usr/xpg4/bin/awk on Solaris.

Thanks for quick reply!

But awk returns:

awk: syntax error near line 1
awk: bailing out near line 1

I'd prefer perl, but awk could also be acceptable.

Did you try nawk?

perl -lane'$x{$F[0]} = $F[1] unless $ARGV eq "xml";
while ($ARGV eq "xml" and m|<id>(.*?)</id>|g) {
  if (exists $x{$1}) {
    print "Found id: $1. Test result: $x{$1}";
    }
  else {
    print "Found id: $1. Test result: N/A";
  }
}' first xml

Or:

perl -lane'$x{$F[0]} = $F[1] unless $ARGV eq "xml";
while ($ARGV eq "xml" and m|<id>(.*?)</id>|g) {
    print "Found id: $1. Test result: ", $x{$1}?$x{$1}:"N/A";
}' first xml