note
btrott
Okay, here's how it works.<p>
Let's first clean it up (which takes all the fun out of
it, but still...):
<code>
$; = $";
$;{Just=>another=>Perl=>Hacker=>} = $/;
print %;
</code>
Looks more understandable, now, right?<p>
The first line sets the value of the special variable $;
to the value of $". $" is the list separator and has the
default value of a space. $; is the subscript separator,
which is used (or used to be used) for multidimensional
array emulation. As explained in [perlvar]. So saying
<code>
$foo{$a, $b, $c}
</code>
really means
<code>
$foo{ join $;, $a, $b, $c }
</code>
Since we've set $; equal to the value of $", the subscript
separator is now a space (' ').<p>
Next line, then:
<code>
$;{Just=>another=>Perl=>Hacker=>} = $/;
</code>
Let's fix it up a bit:
<code>
$;{Just,another,Perl,Hacker,} = $/;
</code>
That actually isn't legal, though, because the special
=> makes it okay to use the barewords. If we replace
them with commas, we'll get errors. And that's why we
need the => after "Hacker"; if we take it off, we get
an error.<p>
Anway, though, now it makes more sense, doesn't it? Because it looks
like the example above, the example from [perlvar]. We're
just assigning to a hash element in the hash %;.<p>
And $/ is the input record separator, the default of which
is a carriage return ("\n"). So we assign that value to
the hash element, so what we really have is something like
this:
<code>
$;{ join ' ', "Just", "another", "Perl", "Hacker", "" }
= "\n";
</code>
Which is just this:
<code>
$;{"Just another Perl Hacker"} = "\n";
</code>
And then we're at the last line:
<code>
print %;
</code>
Which is very simple. We're just printing out the hash
%;, which we just assigned to. In list context, the hash
is flattened to a list. This list, in fact:
<code>
("Just another Perl Hacker", "\n")
</code>
And what happens when we print out that list? Just what
you'd expect:
<code>
Just another Perl Hacker
</code>
So that's it. Doesn't it make you love Perl? :)
22319
24167