in reply to Declare my variable in sysread - Mojo::File::slurp
It's the same trick as in 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.
which is a shorthand forwhile (my $line = <$fh>) {
where, again, my $line appears as anwhile (defined( my $line = readline($fh) )) {
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 | |
by choroba (Cardinal) on Dec 22, 2018 at 00:46 UTC | |
by ikegami (Patriarch) on Dec 22, 2018 at 00:56 UTC | |
Re^2: Declare my variable in sysread - Mojo::File::slurp
by ikegami (Patriarch) on Dec 22, 2018 at 00:52 UTC |
In Section
Seekers of Perl Wisdom