MavEtJu's Distorted View of the World

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";

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

| Share on Facebook | Share on Twitter

URL: http://-
Posted on: 2004-01-19 23:08:02
Commentle: Mavvie, I think "$b" is a special variable
le: as used in "sort { $a $b } blabla"
le: (where you don't have to declare $a or $b even under strict)

le is a friend on irc. Well, friend.... Yes, friend enough :-)

Leave a comment
Back to the main page