All the documentation I've been reading about __DATA__
says stuff like, "the special filehandle" but it's not a filehandle is it?
https://perldoc.perl.org/perldata#Special-Literals
The DATA file handle by default has whatever PerlIO layers were in place when Perl read the file to parse the source."
#!/bin/env perl
open($config, "<test.pl");
$config_copy = $config; # let's me copy a filehandle
while (<$config_copy>) {
print $_; # works just fine
}
$config_copy = __DATA__; # FAIL syntax error does not let me copy a filehandle
while (<$config_copy>) {
print $_;
}
__DATA__
1
2
3
4
5
I basically want to hand a filehandle to a config file reader function OR pass in __DATA__
if it exists, but the reader function is in a different package than the __DATA__
segment, so I need to pass __DATA__
as a parameter because __DATA__
is only accessible from the same package or file it's declared in but perl is not treating __DATA__
like other file handles. It can't be assigned or passed as a function argument.
------ package ConfigReader ------------------
package ConfigReader;
sub ReadConfig {
my ($handle) = @);
while($handle) {
# blah blash
}
}
----------- application ------------------
use ConfigReader;
# it won't let me set a scalar to __DATA__.
# but it lets scalars be set to other file handles.
my $config_handle = __DATA__ # set up default, FAIL syntax error
open($config_handle, "<$config_file_name")
my $configs = ConfigReader::ReadConfig($config_handle);
--------------------------