I had a look at the source of Slurp and I would love to understand how does slurp() work:
sub slurp {
local( $/, @ARGV ) = ( wantarray ? $/ : undef, @_ );
return <ARGV>;
}
Where is the file even opened?
I had a look at the source of Slurp and I would love to understand how does slurp() work:
sub slurp {
local( $/, @ARGV ) = ( wantarray ? $/ : undef, @_ );
return <ARGV>;
}
Where is the file even opened?
See ARGV and $/ in perldoc perlvar.
See also Path::Class:File::slurp.
ARGV is a handle, the file has been opened implicitly.
This snippet puts the filename in @ARGV. The ARGV filehandle implicitly opens the files it sees in @ARGV. This is the same filehandle that we don't see in the diamond operator <> since it's the default filehandle for that operator.
This is the same Perl idiom as:
my $data = do { local( @ARGV, $/ ) = $file; <> };