Live data from Hacker News

The Joy of Perl (1998)

salon.com

61–70 of 82 posts

Re: The Joy of Perl (1998)

#61
post #46
post #39

Earlier quoted context omitted.

It's incredibly confusing if you naively use a list as a default argument, e.g. def foo(some_list=[]): ... some_list.append(3) ... Since the default is constructed when the function is evaluated, it's the same list, but only when the default is used. Or the n00b's attempt to use lambdas: def list_of_lambdas(x): result = [] for n in range(x): result.append(lambda m: n + m) return result for func in list_of_lambdas(3):…

Yes indeed, that's a bug-prone misfeature of Python. Perl and JavaScript both get default arguments right: They make a new array on each call. Perl and JavaScript also get the for-loop closures right as well. In Perl, "for (my $n = ...)" and in JavaScript "for (let n = ...)" will both create a new "cell" each time around the loop, so closures work as expected. (However, MSIE's version of "let" doesn't create a new "c…

Perl has default arguments (outside of Devel::Declare trickery)?

Re: The Joy of Perl (1998)

#62
post #50

Earlier quoted context omitted.

That could be, but I've also noticed a sort of purism where the shell script is ideal because it can be run on any system. (Of course, using bash for the shell isn't a good choice because you can't rely on bash being installed). Personally I reach for Perl as soon as any sort of arithmetic is involved. And even if starting with find(1) is the first choice, it's worth getting to know modules like File::Find because th…

It is unfortunate that those sysadmins are then failing to just go full on awk then rather than those shell scripts. Even alpine has awk installed. docker run --rm alpine awk

alpine doesn't "have awk installed," it's just that BusyBox that has an awk implementation. For real GNU awk you have to install the gawk package.

Re: The Joy of Perl (1998)

#63
post #59
post #55

The thing about perl I still miss is the metaprogramming. It's really amazing to be able to launch a program that writes the "last mile" of code before it starts taking requests.

You can do a lot in Perl with just closures and setting package slots etc., that you would need to use macros for in say Lisps. Still, I agree, there's no real AST and string eval is unsafe and parsing is a real issue. I've started https://metacpan.org/pod/FP::AST::Perl (very unfinished) to solve the code generation issue and hope to generate an AST from the op tree (not sure how feasible, will see). Feel free to tel…

> There’s no real AST

Perl cannot be statically parsed!

> Theorem: Parsing Perl 5 is Undecidable

https://www.perlmonks.org/index.pl?node_id=663393

Re: The Joy of Perl (1998)

#64
post #13

Earlier quoted context omitted.

Some workers complains about their tools. Other just use whatever, fix problems, and make money.

Until you need your next job and you see spending 10 years doing Perl was detrimental to your career...

At least it's fun to write modern Perl code compared to Js which is kind of annoying. Raku is also a very nice language but it's still too slow and hasn't gained much traction. Someone who's proficient in Perl can probably become productive in Python in less than a month.

Re: The Joy of Perl (1998)

#65
post #46

Earlier quoted context omitted.

Yes indeed, that's a bug-prone misfeature of Python. Perl and JavaScript both get default arguments right: They make a new array on each call. Perl and JavaScript also get the for-loop closures right as well. In Perl, "for (my $n = ...)" and in JavaScript "for (let n = ...)" will both create a new "cell" each time around the loop, so closures work as expected. (However, MSIE's version of "let" doesn't create a new "c…

Perl has default arguments (outside of Devel::Declare trickery)?

Yes, built-in since Perl 5.20, released mid 2014.

  use experimental qw(signatures);

  sub plus_one($x = 100) {
      return $x + 1;
  }

  # Says 6.
  say plus_one(5);

  # Says 101.
  say plus_one();
(The subroutine signatures feature is still marked experimental, which is a shame. I use it in virtually all my code, unless I want pre-5.20 compatibility.)

Re: The Joy of Perl (1998)

#66
post #58
post #43

If perl6 had not been the Duke Nukem Forever of programming languages, I'd probably still be coding in Perl, but Ruby just came along and offered a very similaly spirited playground. And then I found lisp and realized that my late perl code was very lisp-ish anyway.

Did Duke Nukem Forever change its name? Perl 6 has. It's called Raku now ( https://raku.org using the #rakulang tag on social media). And it is very much alive and ready for production.

No, but it was so long in the making that I had discovered alternatives and mastered them.

I still write perl5 sometimes but none of perl6 features convinced me to install an interpreter anywhere when I already have ruby or python on the machine.

Re: The Joy of Perl (1998)

#67
post #66
post #58

Earlier quoted context omitted.

Did Duke Nukem Forever change its name? Perl 6 has. It's called Raku now ( https://raku.org using the #rakulang tag on social media). And it is very much alive and ready for production.

No, but it was so long in the making that I had discovered alternatives and mastered them. I still write perl5 sometimes but none of perl6 features convinced me to install an interpreter anywhere when I already have ruby or python on the machine.

Too bad. And now it is too late, because Perl 6 has been renamed to Raku (https://raku.org using the #rakulang tag on social media). Which features would convince you to install Raku?

Re: The Joy of Perl (1998)

#68
post #63
post #59

Earlier quoted context omitted.

You can do a lot in Perl with just closures and setting package slots etc., that you would need to use macros for in say Lisps. Still, I agree, there's no real AST and string eval is unsafe and parsing is a real issue. I've started https://metacpan.org/pod/FP::AST::Perl (very unfinished) to solve the code generation issue and hope to generate an AST from the op tree (not sure how feasible, will see). Feel free to tel…

> There’s no real AST Perl cannot be statically parsed! > Theorem: Parsing Perl 5 is Undecidable https://www.perlmonks.org/index.pl?node_id=663393

> Perl cannot be statically parsed!

My usage (modifying syntax / extending the compiler when running Perl programs) doesn't need static parsing. What I need is a way to leverage the existing infrastructure in the interpreter for parsing in a way that's compatible with most modules/usages. AFAIK the parser in perl goes directly from source to an OP tree (modulo running other Perl code on the go that modifies the parsing state, which is the reason for the undecidability), it would be cool if it didn't go to an OP tree but something more AST instead, but it might not be feasible to change perl to do that because of modules working on the op tree (if anyone wants to help figure out how much this is true, please do); because of that I'll instead look into converting the op tree into an AST. I've been told the op tree does have additional info that might make that feasible. Notabene, B::Deparse exists, which is somewhat of a proof that this works, although there are limitations, whether they matter is part of what I need to find out.

Re: The Joy of Perl (1998)

#69
post #64

Earlier quoted context omitted.

Until you need your next job and you see spending 10 years doing Perl was detrimental to your career...

At least it's fun to write modern Perl code compared to Js which is kind of annoying. Raku is also a very nice language but it's still too slow and hasn't gained much traction. Someone who's proficient in Perl can probably become productive in Python in less than a month.

I was traditionally the farthest thing from a JS callback hell fanboy, but, using modern JS with async/await and “classes” (yes I realize it’s syntactic sugar, prototypical inheritances, yada yada yada), it’s not bad. I haven’t played with TypeScript in a few years, but I’m looking to get back into it.

But why fool with Perl at all - especially Raku since it’s basically a new language that doesn’t have the widespread support of Python or God forbid PHP?

Re: The Joy of Perl (1998)

#70
post #65

Earlier quoted context omitted.

Perl has default arguments (outside of Devel::Declare trickery)?

Yes, built-in since Perl 5.20, released mid 2014. use experimental qw(signatures); sub plus_one($x = 100) { return $x + 1; } # Says 6. say plus_one(5); # Says 101. say plus_one(); (The subroutine signatures feature is still marked experimental, which is a shame. I use it in virtually all my code, unless I want pre-5.20 compatibility.)

Neat, thanks! I can't use it unfortunately (the little Perl I still write targets 5.8 on ancient CentOS, but that's not the language's fault).

Good to see it still evolving!

Post reply on HN