stevendel has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl my $handle1; open($handle1, "< /tmp/1") || die "Input file does not exist.\n"; # Case 1 GetFileContentsViaScalar(\*$handle1); close($handle1); sub GetFileContentsViaScalar { my $FH = shift; print "SHIFT:\n"; { local($/); print <$FH>; } }
#!/usr/bin/perl my $handle1; open($handle1, "< /tmp/1") || die "Input file does not exist.\n"; # Case 2 -- fails GetFileContentsViaFnHash(\*$handle1); close($handle1); sub GetFileContentsViaFnHash { my %test; $test{FH} = shift; print "Function hash:\n"; { local($/); print <$test{FH}>; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting file handle glob name instead of contents
by TGI (Parson) on Sep 10, 2008 at 18:08 UTC | |
by stevendel (Novice) on Sep 10, 2008 at 18:36 UTC | |
|
Re: Getting file handle glob name instead of contents
by Fletch (Bishop) on Sep 10, 2008 at 17:36 UTC | |
|
Re: Getting file handle glob name instead of contents
by Tanktalus (Canon) on Sep 10, 2008 at 17:41 UTC |