Whenever I want to simulate input and output to a file descriptor, I often use references to DATA and STDOUT respectively:
use strict; use warnings; use autodie;
Outputs:
Hello World
However, in Borodinโs recent answer , it was demonstrated that in fact there is no need to take the link. Instead, a simple assignment is enough:
my $infh = *DATA;
So I created the following script to compare and contrast the difference between these two methods:
use strict; use warnings; use Fcntl qw(:seek);
Outputs:
Name Value ref() readline() \*DATA GLOB(0x7fdc43027e70) GLOB Hello World *DATA *main::DATA Hello World
When it comes to transmitting and reading from a file descriptor, there is no difference between a type character and a type reference.
Switching from testing to a research research form shows the following perldoc pages:
The first link suggests either use. So far, the second gives a list of other alternatives, but mentions how the reference notation is needed if we want to bless the variable. No other difference is proposed.
Is there a functional or preferred style difference between these two indirect file descriptors?
my $fh = \*DATA;my $fh = *DATA;
perl
Miller
source share