Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Things are not what they seem like.

by Abigail (Deacon)
on Jul 13, 2000 at 09:02 UTC ( [id://22319] : obfuscated . print w/replies, xml ) Need Help??

$; # A lone dollar? =$"; # Pod? $; # The return of the lone dollar? {Just=>another=>Perl=>Hacker=>} # Bare block? =$/; # More pod? print%; # No right operand for %?

-- Abigail

Replies are listed 'Best First'.
(zdog) RE: Things are not what they seem like.
by zdog (Priest) on Aug 01, 2000 at 06:19 UTC
    Great post!

    At first I thought, what the...? But then I realized that $; was the name of a variable. Next I say, "AHA! Does it work with use strict ?" At first I didn't think so since I thought that you would have to declare $; by saying "my $;", but then I hopped on over to perlvar and realized that $; is a "special variable" and that set me straight.

    And a few moments later, I said, "Doh! I should have just read btrott's post and it would have saved me a lot of trouble. Oh, well."

    Zenon Zabinski | zdog |

Re: Things are not what they seem like.
by manav (Scribe) on Mar 03, 2005 at 11:17 UTC
    Copy/Paste this code into a script(say and then
    perl -MO=Deparse

RE: Things are not what they seem like.
by Russ (Deacon) on Jul 13, 2000 at 11:01 UTC
    Okay, now this is just entirely too cool!

    I especially love the use of ; in new and previously unknown (for me) ways.


    Brainbench 'Most Valuable Professional' for Perl

RE: Things are not what they seem like.
by princepawn (Parson) on Jul 25, 2000 at 00:04 UTC
    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.
      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!
      A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Things are not what they seem like.
by Lucky (Scribe) on Dec 05, 2001 at 16:05 UTC
    It's probably the most beatiful things I saw. Great!!!
Re: Things are not what they seem like.
by RonW (Parson) on Jan 15, 2016 at 18:30 UTC

    Wow! Amazing.

    Pity that Abigail is no longer on PM.