http://www.perlmonks.org?node_id=1227575


in reply to Declare my variable in sysread - Mojo::File::slurp

It's the same trick as in
while (my $line = <$fh>) {
which is a shorthand for
while (defined( my $line = readline($fh) )) {
where, again, my $line appears as an argument operand of = which in turn is an argument operand of defined. my has two effects, one compile time and one run time. In compile time, you declare a lexical variable, and in runtime, you use it as an lvalue (i.e. assign a value to it). Variables declared in block conditions (if, while, unless, until) are accessible until the last conditional operator block.
if (my $x = func()) { print "$x accesible here"; } elsif ($x eq 0) { # even here, print "and also here: $x"; }

Updated.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Declare my variable in sysread - Mojo::File::slurp
by ikegami (Patriarch) on Dec 22, 2018 at 00:43 UTC

    my $line appears as an argument of defined.

    No, it doesn't. It's an operand of =, not defined.

      But the = is, in turn, an argument operand to defined.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        Yes, = is an operand of defined, but your whole point is that sysread($file, my $buf, ...) is like defined(my $line), but your code doesn't use defined(my $line).

Re^2: Declare my variable in sysread - Mojo::File::slurp
by ikegami (Patriarch) on Dec 22, 2018 at 00:52 UTC

    my $line appears as an argument of = which in turn is an argument of defined.

    You're still claiming my $line is an argument of defined, and it's not. Operators have operands (not arguments), and the variable $line is defined's operand.