Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

chromatic (983)

chromatic
  (email not shown publicly)
http://wgz.org/chromatic/

Blog Information [technorati.com] Profile for chr0matic [technorati.com]

Journal of chromatic (983)

Thursday April 17, 2003
06:52 PM

lvalue typeglobs

[ #11712 ]

I've always wondered if this would work, but never tried it until now. It worked on the first try. Does that say more about me or Perl?

#!/usr/bin/perl -w

use strict;

sub installsub: lvalue
{
    my $glob = shift;
    no strict 'refs';
    *{ $glob };
}

installsub( 'foo' ) = sub { print "Foo!\n" };
foo();

Of course, that's not bad enough:

for my $sub (qw( bar baz ))
{
    installsub( $sub ) = sub { print "$sub\n" };
    __PACKAGE__->can( $sub )->();
}

Worse yet, I have an actual factual practical use in mind.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.