Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Ninjew
Aug 3, 2004

God, I love perl. No other language gives you the same kind of freedom to cheat and create very clever solutions to problems. Have a problem that would be best solved using a functional language like LISP? Just set no strict refs, and off you go! It is very refreshing to be able to actually program in a way that is not limited or constrained by the language. Don't listen to anyone who says that this flexibility is a negative aspect of perl, rather than a positive one. They are very wrong.

I have found the camel book to be utterly useless. Its fun to read, but fails in actually being a good handbook for the language. I've found perl's man pages to be infinitely more readable, concise, and useful.

For new perl programmers, the must read man page (besides perlre) is perlref. Without understanding and using references, it is impossible to harness the full flexibility of the language.

Adbot
ADBOT LOVES YOU

Ninjew
Aug 3, 2004

Stabby McDamage posted:

- Subroutines can be passed as variables ("closures").


Actually, this isn't what a closure is. A closure is a logical concept that comes along with perl being a formal language: in any abstract block of code (subroutine, anonymous block), you can have free variables; that is, variables that aren't declared (lets assume that we have strict vars on) , or, in logical terms, aren't bound. Perl supports closures, in that, if that variable is bound outside of that block of code, it is considered as a constant, not a variable, in that code. For example:

code:
my $teh = "asdf\n";
{
    print $teh;
}
This is an example of a closure, although a rather pointless one. Or, in a little more practical example:
code:
use strict;
my $asdf = "asdf\n";
my $ref = sub { my $foo = shift; print "$foo$asdf"; };
&{$ref}("teh")

OUTPUT:
tehasdf
The fact that perl supports creating references to subroutines does not imply that it supports closures - that is, allowing externally bound variables to be bound inside blocks where they appear as free (unbound) variables.

Ninjew
Aug 3, 2004

floWenoL posted:

I'm not sure what exactly you mean by "constant", but if you mean the value of the variable is fixed to whatever the value is at the time of the creation of the closure, it's not true:

You're right- I got closures from formal logic mixed up with perl's implementation.

floWenoL posted:

I'm also not sure why you associate the behavior of "no strict refs" with functional languages, given that that is a feature shared by most, if not all, dynamic languages, functional or not.

I was giving an example of perl's flexibility, not comparing it to other languages.

  • Locked thread