MavEtJu's Distorted View of the World - Perl

Perl voodoo

Back to index

Perl voodoo

Posted on 2004-01-19 22:55:53, modified on 2006-01-09 16:29:21
Tags: Coding, Perl

A friend of me came up with this piece of code: (click on URL later). If you run it (with 5.6.1 or 5.8) it will complain that $c isn't specified. But then, if you rename the *c and $c to *b and $b, the program suddenly works.

This is even worse than black magic....

#!/usr/bin/perl -w
use strict;

package testexport;
sub testing {
    my $KEY = shift;
    print "KEY=[$KEY]\n";

    my $a = $::TEST_SINGLE;
    print "a=[$a]\n";

#   my $b = eval "\$::$KEY";
#   print "b=[$b]\n";

    no strict 'refs';
    local *c = $::{$KEY};
    use strict 'refs';
    print "c=[$c]\n";
}

package main;
$main::TEST_SINGLE = "hallo";
#my $TEST_SINGLE = "hallo";
testexport::testing("TEST_SINGLE");

(now rename the "local *c" to "local *b" and "$c" to "$b"...)


Show comment | Share on Facebook | Share on Twitter