Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is the sentiment I've been seeing online, especially here.

1/3 of the posts here are "<old tool that already exists in a stable, mature codebase> in {rust|go|whatevernewlanguagecomesnextweek} released v0.0.1"

Perl is a great language, that does it's job for many, many things, especially with CPAN, and it has been doing so for years. You can buy a 20yo book on perl, and 99.99% of the example code from that book still works, and same goes for projects from that era (which cannot be said for python, where developers and distro mainanters seem to enjoy removing usable, mature projects, just because they're written for python2.7 and incompatible with 3+).

If I have to write a script once, that I can forget about, and just expect it to run for years, perl will always be my first choice.



>99.99% of the example code

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:

    $num = 3;
    print $num;
new:

    my $num = 3;
    print $num;


It works without "my" too :)

$ perl

    $num = 3;

    print $num;
3

(perl v5.32.1, without "use strict" of course)


Ah,TIL.

As I always used

use strict; use warnings;

as something like muscle memory, I didn't know this.


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


According to Google, a one off I wrote in Perl in 1998 is still in use at the lab I wrote it in.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: