www.webdeveloper.com
Results 1 to 3 of 3

Thread: Name sub routine from data?

Hybrid View

  1. #1
    Join Date
    Jun 2008
    Posts
    223

    Name sub routine from data?

    Is it possible to assign a sub routine a name from a variable?

    Code:
    sub $variable {something here}
    If this can be done it would save me writing to a whole extra file every time I add something (which s what I'm doing at the moment). I already have the names in a tiny FFDB.

    Any ideas?

    Thanks

  2. #2
    Join Date
    Oct 2007
    Location
    Vienna, Austria
    Posts
    389
    You can do so using globs:

    Code:
    my $variable = 'foo';
    {
        no strict 'vars';
        *$variable = sub { print "Foo!\n"; };
    }
    foo();
    I bet you don't really need to resort to it but here's an answer to the question.

    update: Added no strict vars;
    Last edited by Sixtease; 12-22-2012 at 03:00 AM.

  3. #3
    Join Date
    Jun 2008
    Posts
    223
    Thanks Sixtease, I'll give that a try.

    I'm trying to keep things small in my blog code and this is for the categories stuff so if I don't have to do something extra, then all well and good.

    Merry Christmas and Happy New Year

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles