Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

RE: Things are not what they seem like.

by princepawn (Parson)
on Jul 25, 2000 at 00:04 UTC ( #24167=note: print w/replies, xml ) Need Help??

in reply to Things are not what they seem like.

I wouldlike some explanation of this code... you are clearly thundering from the great heights with this code, but w/out explanation, a poor sap like me is left in the dark.
  • Comment on RE: Things are not what they seem like.

Replies are listed 'Best First'.
RE: RE: Things are not what they seem like.
by btrott (Parson) on Jul 25, 2000 at 00:22 UTC
    Okay, here's how it works.

    Let's first clean it up (which takes all the fun out of it, but still...):

    $; = $"; $;{Just=>another=>Perl=>Hacker=>} = $/; print %;
    Looks more understandable, now, right?

    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

    $foo{$a, $b, $c}
    really means
    $foo{ join $;, $a, $b, $c }
    Since we've set $; equal to the value of $", the subscript separator is now a space (' ').

    Next line, then:

    $;{Just=>another=>Perl=>Hacker=>} = $/;
    Let's fix it up a bit:
    $;{Just,another,Perl,Hacker,} = $/;
    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.

    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 %;.

    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:

    $;{ join ' ', "Just", "another", "Perl", "Hacker", "" } = "\n";
    Which is just this:
    $;{"Just another Perl Hacker"} = "\n";
    And then we're at the last line:
    print %;
    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:
    ("Just another Perl Hacker", "\n")
    And what happens when we print out that list? Just what you'd expect:
    Just another Perl Hacker
    So that's it. Doesn't it make you love Perl? :)
      Excelent use of special varibles, and excelent explanation!
      oh wow! This is Brilliant, Awesome stuff, Great explanation. Thanks a ton, and Oh Yeah it makes me go mad about Perl!

      Excellent btrott

      Thank you very much

      I cannot + vote you enough on this one

      To some, Perl is an art form. To others it is a religion. What is it to you?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://24167]
[1nickt]: Ah, you got Linus' fave? With Ubuntu? 4k display?
[1nickt]: ( The 17" monster I just bought is for my wife, who doesn;t leave the house with it...)
[Corion]: 1nickt: No, I'm using it with Windows 10, but with the 4k display, yes. It's a very nice build IMO, and relatively sturdy. Also, it got 8 or 9 on the ifixit repair scale, which I consider good
[Corion]: ... especially as I expect to have to replace the battery set in two or three years' time
[1nickt]: Nice. So happy that Dells are still user-repairable. Unusual these days.
[1nickt]: I will certainly not be buying any more Macs.
[Corion]: 1nickt: Yeah, or at least, I hopoe so ;)

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (13)
As of 2017-03-27 13:13 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.