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 ]

Shlomi Fish (918)

Shlomi Fish
AOL IM: ShlomiFish (Add Buddy, Send Message)
Yahoo! ID: shlomif2 (Add User, Send Message)

I'm a hacker of Perl, C, Shell, and occasionally other languages. Perl is my favourite language by far. I'm a member of the Israeli Perl Mongers, and contribute to and advocate open-source technologies. Technorati Profile []

Journal of Shlomi Fish (918)

Wednesday July 20, 2005
05:11 AM

Retro-programming using Acme::Gosub

[ #25803 ]

Yesterday I uploaded the first public release of Acme::Gosub to CPAN. This allows you to emulate BASIC's "GOSUB" and "RETURN" statements in Perl. It all started a long time ago when I thought that Perl's "goto EXPR" statement was powerful enough to emulate goto, by keeping a stack of labels, and where RETURN would be something like goto pop(@labels).

Then I came to the idea of writing a module to do it. I searched CPAN for gosub but couldn't find anything relevant so the coast was clear. However, I then got stucked up in a technicality. A few days ago, I was able to find a way to resolve it, and so set down to write the module.

I started from which I knew utilized a code filter. My needs were simpler except for trying to have a "gosub EXPR;" as a statement, for which I tricked Text::Balanced into doing it by prepending a leading semicolon and then asking to find a match code-block that was delimited by semi-colons. (it's a kludge, but it works).

I finished it in one afternoon, and then uploaded it. It has a nice test-suite with some funky functions that make use of gosub. At the moment, it has some glaring bugs and limitations, but hopefully they will be resolved in a future work.

So now I give you the Acme::Gosub JAPH:


use strict;
use warnings;

use Acme::Gosub;

my @japh = ("Just another", " Perl", " and Acme::Gosub", " Hacker\n");

sub print_japh
    my $print_me;
    $print_me = $japh[0];
    gosub PRINT;
    $print_me = $japh[1];
    gosub PRINT;
    $print_me = $japh[2];
    gosub PRINT;
    $print_me = $japh[3];
    gosub PRINT;
    print $print_me;

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.