Look Ma! More Perl!

;_; (aka QQ)

Again from Learn Perl in about 2 hours 30 minutes:

Unlike almost every other major programming language, Perl calls by reference. This means that the variables or values available inside the body of a subroutine are not copies of the originals. They are the originals.

You're killing me, Perl.

(Bee tea dub: Nice doc on perl command line options here -- -l is a nice alternative to say)

Padre fails

In the "won't behave" category, add still being unable to install Padre, the at least implicitly recommended IDE for Perl, with cpanm or cpan. And I'm not the only person. What a versioning mess.

Loops are fun!

And finally, this jive on loops is more note-to-self, but isn't especially intuitive either:

Basic C-style for loops are available too. Notice how we put a my inside the for statement, declaring $i only for the scope of the loop:

for(my $i = 0; $i < scalar @array; $i++) {
    print $i, ": ", $array[$i];
}
# $i has ceased to exist here, which is much tidier.

This kind of for loop is considered old-fashioned and should be avoided where possible. Native iteration over a list is much nicer. Note: unlike PHP, the for and foreach keywords are synonyms. Just use whatever looks most readable:

foreach my $string ( @array ) {
    print $string;
}

... and it's intuitive, too!

Remembering that $#array gets you the array's length (argh. Of course)...

If you do need the indices, the range operator .. creates an anonymous list of integers:

foreach my $i ( 0 .. $#array ) {
    print $i, ": ", $array[$i];
}

You can't iterate over a hash. However, you can iterate over its keys. Use the keys built-in function to retrieve an array containing all the keys of a hash. Then use the foreach approach that we used for arrays:

foreach my $key (keys %scientists) {
    print $key, ": ", $scientists{$key};
}

Since a hash has no underlying order, the keys may be returned in any order. Use the sort built-in function to sort the array of keys alphabetically beforehand:

foreach my $key (sort keys %scientists) {
    print $key, ": ", $scientists{$key};
}

If you don't provide an explicit iterator, Perl uses a default iterator, $_. $_ is the first and friendliest of the built-in variables:

foreach ( @array ) {
    print $_;
}

Packages are also fun!!!

Packages and modules are two completely separate and distinct features of the Perl programming language. The fact that they both use the same double colon delimiter is a huge red herring. It is possible to switch packages multiple times over the course of a script or module, and it is possible to use the same package declaration in multiple locations in multiple files.

You can see where this is going, right? I was already loling in my head at how convoluted the two concepts could get by this point. -mfn

Calling require Foo::Bar does not look for and load a file with a package Foo::Bar declaration somewhere inside it, nor does it necessarily load subroutines in the Foo::Bar namespace. Calling require Foo::Bar merely loads a file called Foo/Bar.pm, which need not have any kind of package declaration inside it at all, and in fact might declare package Baz::Qux and other nonsense inside it for all you know.

Likewise, a subroutine call Baz::Qux::processThis() need not necessarily have been declared inside a file named Baz/Qux.pm. It could have been declared literally anywhere. This next bit at the close of the packages/modules section is probably best considered a universally applicable tenet of programming:

However, it is important that you do not take [any convention or best practice] for granted, because one day you will meet code produced by a madman.

I don't think I'd ever recommend Perl for someone's first programming language. Probably not even their second (I think I'd recommend 6502 assembler (because you should know, in at least a simplest case, how the things work) and then C# at this point).

VIm is not the IDE you were looking for

And here's a VIm related issue...

I'm trying to trick to run :!perl % to run what I'm editing in a shell, but right now VIm is opening PowerShell, which is executing my PowerShell profile and dropping me into the directory I have PowerShell navigate to by default. When it's there, it can't find the file in %, of course.

I tried Open Perl IDE, which was rough running, and there's some sentiment that it's not working well with recent versions of Windows.

Seems it would be insanely easy (all things considered) to write a Perl IDE for Windows (and Open Perl IDE had 131 downloads from SourceForge (that we know is evil now) this week) since Perl provides its own debugger for goodness' sake, but it doesn't appear to have been done.

WHAT A PAIN.

Others feel your pain.

from here, and the first quote is from the page's author:

2014-09-08 09:20:04 by Sam:

PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil perpetrated by skilled but perverted professionals.

... or, better yet...

2014-09-07 05:37:51 by David Mitchell:

Dear God. Not[e] to self: never use perl.

Labels: