I'd do it this way, for a variety of reasons. The subroutine nested within the block bothers me, and I think there's a better way to handle the file reading:
#!/usr/bin/perl -w
use strict;
local *EXA;
local *INFO;
opendir (EXA, "/export/home/cad/data/products") || die "no dir?: $!";
foreach my $name(sort readdir (EXA)) {
print "$name\n";
open(INFO, "/export/home/cad/data/products/$name/source/$name.bom"
+) || die "no dir: $!";
while (my $line = <INFO>) {
$line=~tr/(//d; #Cut out all the exa garbage
$line=~ s/COMP//;
$line=~ s/BOARDPLACEMENT_BOM brd//;
print "\n $line ";
}
close(INFO) ;
print "\n ------------------------ \n";
}
closedir(EXA);
Not only is this a little cleaner, and it gets rid of the troublesome nested subroutine, it avoids reading a potentially large file into memory. If you're just going to iterate over each line later, why use an array? (Acceptible answer, "When you need to open and close the file as quickly as possible.")
Explanation of the local: I like declaring typeglobs, it's fun. If you're really particular, wrap the whole bit in a block, from before the local statements to after the close statement, and this can be part of a bigger program that might also have filehandles named EXA and INFO. You won't clobber them here.