Hi Monks,
I have a question about some code I saw in Mojo::File. In the slurp method, you see this:
sub slurp {
my $self = shift;
CORE::open my $file, '<', $$self or croak qq{Can't open file "$$self
+": $!};
my $ret = my $content = '';
<b>while ($ret = $file->sysread(my $buffer, 131072, 0)) { $content .
+= $buffer }</b>
croak qq{Can't read from file "$$self": $!} unless defined $ret;
return $content;
}
Inside the while, you see my $buffer used as the first argument to sysread, and then used in the body of the while loop. I've never seen this before, where you declare a variable as an argument and then access it later. Can anyone explain how this works? Is the body of the while loop able to access $buffer because the while loop's scope includes anything in the parentheses or the body of the loop?