[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] subs, pod, package & sectioning



I agree with Matthias' comments, so I won't repeat them here.

>For the later case, I'm scanning each line with a regex that hits on all
>the instances I'm concerned with, then useing a case statement. Here is the
>regex:
>^(package|BEGIN|END|sub|=head1|=pod|__END__|__DATA__)([ \t]+[^\s;\{])*|(^
>*###)

I've seen people, including myself, define subs thusly:

sub
foo
{
...
}

This is so I can easily find the definition of foo by searching for ^foo in
editors like vi (being many of my MacPerl scripts also run on and are
edited on Unix). I would expect foo to appear in the menu, probably
pointing at the "sub", but at the foo would be ok too.

>Once in a package, BEGIN and END act as special subroutines, so I create
>indexes for them:
>BEGIN|END

A couple of things here. First, BEGIN and END don't have to appear in a
package (if they don't, they're in main), and second, they aren't
subroutines, they're blocks. This isn't just semantic pickiness, there are
differences in what variables are available and how they're set up.

>Are their any other keyword/constructs that would be useful to index?

A couple of things I can think of:

- A script can have:

sub a;

which *declares* subroutine a, it's *defined* elsewhere. I would think the
definition's location is what should appear in the menu, not the
declaration's location.

- In:

package x;
sub b {...}
sub y::c {...}
package main;
sub x::d {...}
sub x::y::z::e {...}

there are four packages (x, y, main, x::y::z) and four subroutines--b in
package x, c in package y, d in package x, and e in package x::y::z (poor
main is empty :-(). Nowhere does "package y" or "package x::y::z" have to
appear, and there's no explicit hierarchy, so package x and package x::y::z
are unrelated except as the script relates them.

- The construct:

sub b ($@%*;\@\%) {...}

defines subroutine b with a prototype. This particular prototype is
completely unrealistic, but it lists all the characters that can currently
occur in a prototype. You're more likely to see things like:

sub c ($$$) {...}
sub d ($@) {...}
sub e (\%\%;$$) {...}

etc.

Prototypes can also appear in declarations:

sub f ($$$);

Hope this helps,
Brian



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch