How to map the values of an array in perl?

Hi,

I have 2 arrays:

@names=qw(amith veena chaitra);
@files=qw(file.txt file1.txt file3.txt);

There is one to one relationship between names and files.

There needs to be mapping created between names and files.

The output should be like this:

amith --> file.txt
veena ---> file1.txt
chaitra ---> file3.txt

How can i implement hash concept to these?

There may be "n" number of records like this. Arrays or hash will be better.

I tried like this:

for($i=0;$i<=$#names;$i++) {
print "$names[$i] ---- $files[$i]\n";
}

Is there any better performance code than this?

Regards
Vanitha

I'm not sure what you're trying to achieve...it will be very easy to place the array data in a hash in exactly the same way that you're printing your output, but you'd then need to print the hash, so don't see a performance gain there!

Hi,

I am just trying to do one -to one mapping. Map the elements in first array with second array.

How is it possible in hash?

Regards
Vanitha

You can convert the two arrays into hash and print it like below,

@hash{@names}=@files;
foreach(keys %hash){
print "$_ ---- $hash{$_}\n";
}