Re:Perl Data Language: Scientific Computing with Perl
by ajsnigrutin on Wednesday June 09, 2021 @07:41AM
(#27446747)
It works without "my" too :)
$ perl
$num = 3;
print $num;
3(perl v5.32.1, without "use strict" of course)
Re:Perl Data Language: Scientific Computing with Perl
by anthk on Wednesday June 09, 2021 @01:32PM
(#27450691)
Ah,TIL.
As I always used
use strict; use warnings;
as something like muscle memory, I didn't know this.
Re:Perl Data Language: Scientific Computing with Perl
by b2gills on Wednesday June 16, 2021 @09:56AM
(#27528533)
One of the things that `use strict` does is enable `use strict "vars"`.
use strict;
no strict qw(vars);
$foo = $bar;
That's part of the reason `use strict` is recommended.---
The other major reason is `"refs"`, which disable symbolic refs. Honestly this is *THE* main reason I recommend `use strict`.
Symbolic refs are how you did arrays of arrays prior to Perl5. (Among other uses.)
use 4.0;
@a = 'b','c';
@b = (1, 2);
@c = (3, 4);
print $a[1]->[1], "\n"; # 4
That can be a security risk if an attacker can insert or change strings in `@a`.It isn't (generally) needed anymore of course.
use 5.0;
my @a = ( \[1,2], \[3,4] );
print $a[1]->[1], "\n"; # 4
(The only reason `@b` and `@c` existed was to symbolically reference them.)
Orelly's Perl books from the CD bookshelf still work.
Just declare a variable with "my =" in front of it (just once), and everything will work as usual:
old:
new: