monkfan has asked for the wisdom of the Perl Monks concerning the following question:
However, instead of giving the file contents as its values, it gives "undef" instead, like this.#!/usr/bin/perl -w use Data::Dumper; use strict; my $mydir = 'mysubdir\*'; my @filear = glob($mydir); my %hash = make_hash(@filear); sub make_hash { (local $/)=undef; my (@files,%hash); @files = @_; foreach my $file ( @files ) { open( my $fh, $file ) or next; $hash{$file} = <$file>; # This line gives "unopened filehandle wa +rning" }; return %hash; } print Dumper \%hash;
Please advice what's wrong with my code above.$VAR1 = { 'mysubdir\\file1.txt' => undef, 'mysubdir\\file2.txt' => undef };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unopened Filehandle Problem
by steves (Curate) on Nov 06, 2004 at 16:38 UTC | |
|
Re: Unopened Filehandle Problem
by zentara (Cardinal) on Nov 07, 2004 at 13:11 UTC |