Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Declare my variable in sysread - Mojo::File::slurp

by choroba (Archbishop)
on Dec 21, 2018 at 16:59 UTC ( #1227575=note: print w/replies, xml ) Need Help??


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 (Pope) 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 (Pope) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1227575]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2019-12-15 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?