in reply to Directly assigning Filehandle

use lexical filehandles:
sub read_file { my $name = shift; open my $fh,"<",$name or die "can't open $name; $!"; while (<$fh>) { chomp; read_file($_) if -f $_; } close $fh; }
untested for obvious reasons :-)

Replies are listed 'Best First'.
Re^2: Directly assigning Filehandle
by ikegami (Patriarch) on May 04, 2005 at 16:04 UTC

    Unfortunately, the three argument open is not backwards compatible with 5.6.x. OTOH,
    open my $fh,"< $name" or die "can't open $name; $!";
    would work.

      5.6.x introduced both lexical filehandles and three-argument open.

        oops, you're right. I tested it before posting, but I must have had a mistake in my test.