Slash Boxes
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)

  (email not shown publicly)

Blog Information [] Profile for chr0matic []

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

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.
More | Login | Reply
Loading... please wait.