Again from Learn Perl in about 2 hours 30 minutes:

Perl variables come in three types: scalars, arrays and hashes. Each type has its own sigil: $, @ and % respectively.

I started dropping which was which in my head trying to remember what the character was for grabbing a reference, and decided it was mnemonic time.

Taking a closer look, the mnemonic's already there, and is painfully obvious. For those even thicker than me (ha), they are...

  • $ is for S is for Scalar.
  • @ is for A is for Array
  • % is for, well, I guess H, since it's Hash.

Okay, the "H" isn't quite as obvious as it could be (# would probably be more obvious, and then we could use // for comments, but I digress ;^D), but the first two are as obvious as they can get.

Duh.

And as for grabbing references, that's a backlash. Because why not, I guess.

A reference is created using a backslash.

my $colour = "Indigo";
my $scalarRef = \$colour;

Any time you would use the name of a variable, you can instead just put some braces in, and, within the braces, put a reference to a variable instead.

print $colour; # "Indigo"
print $scalarRef; # e.g. "SCALAR(0x182c180)"
print ${ $scalarRef }; # "Indigo"

As long as the result is not ambiguous, you can omit the braces too:

print $$scalarRef; # "Indigo"

or, for an array...

my @owners = @{ $ownersRef };

In other news, I was trying to install Padre with Strawberry Perl, and was following the apparently years old suggestions to the letter. After trying to cpanm Wx, however, I got this encouraging bit in a failed build log:

Test Summary Report
    t/04_userdata.t (Wstat: 0 Tests: 65 Failed: 0)
    TODO passed: 25, 33, 41, 57
    t/14_eh_die.t (Wstat: 0 Tests: 5 Failed: 0)
    Parse errors: Bad plan. You planned 6 tests but ran 5.
    Files=23, Tests=772, 444 wallclock secs ( 0.27 usr + 0.34 sys = 0.61 CPU)
    Result: FAIL

This sort of thing has apparently happened before and may be some sort of version conflict.

Idk, when I was using fink on OS X (I think brew is the more popular package manager for OS X now), I never hit this sort of issue, which was pretty impressive. You'd think Perl on Windows would be popular enough to be pretty painless. It's not.

Labels: ,