in reply to Filehandles, scope and warnings.

Apart from using 'my', there seem to be other good habits to get into from reading the OP:

- using close,

- avoiding unecessary loops that repeat the same functionality - for example the OP code opens and reopens the same file and slurps it for each line of another file.

- if the container for the filehandle goes out of scope inconveniently, just transfer it to one that does have adequate scope.

Or to put that all into code:

#!/usr/bin/perl use strict; use warnings; open my $fh1, "file1" or die "$!: file1"; my $fh2; my @file2; { local $/ = undef; open my $fh, "file2" or die "$!: file2"; $fh2 = $fh; @file2 = <$fh>; } close $fh2; # could have closed in the above block, but just illustrat +ing a point about scope here while (<$fh1>) { print; print @file2; } close $fh1;

-M

Free your mind