[Zope] Re: [Zope-Perl] Send me your Perl Methods

Andy McKay andym@ActiveState.com
Wed, 6 Sep 2000 13:58:55 -0700


Or maybe using a perl module that doesnt exist in Python? I was looking at
MP3::Napster the other day but Im stuck on Windows.

----- Original Message -----
From: "Gisle Aas" <gisle@ActiveState.com>
To: "Michel Pelletier" <michel@digicool.com>
Cc: <zope-perl@zope.org>; <amos@digicool.com>
Sent: Wednesday, September 06, 2000 1:33 PM
Subject: Re: [Zope-Perl] Send me your Perl Methods


> Michel Pelletier <michel@digicool.com> writes:
>
> > Gisle Aas wrote:
> > >
> > >
> > > I'm also looking for interesting examples :-)
> > >
> > > Do you have any interesting PythonMethod examples?  I can probably
> > > translate it to perl for you.
> >
> > Yes, I thought that was a good approach.  I don't really have any good
> > python methods either, but I can come up with some.
> >
> > Here's an algorithm I did in the Globbing Lexicon component of Zope.
> > This turns a string into 'digrams' Which is a common wild-card searching
> > datastructure.  So:
> >
> >   bob => ['$b', 'bo', 'ob', 'b$']
> >   python => ['$p', 'py', 'yt', 'th', 'ho', 'on', 'n$']
> >
> > Dollar signs mark the beginning and ending of the word.
> >
> > def digram(word):
> >     """  """
> >     digrams = []
> >     digrams.append('$' + word[0]) # mark the beginning
> >
> >     for i in range(len(word)):
> >         digrams.append(word[i:i+2])
> >
> >     digrams[-1] = digrams[-1] + '$' # mark the end
> >
> >     return digrams
> >
> > There's probably a better way to do it in Python, and this should be
> > Perl's forte.  Can someone come up with a reasonably cool Perl method
> > that did this?
>
> sub digram {
>    my $word = shift;
>    my @digrams;
>    push(@digrams, '$' . substr($word, 0, 1));
>    push(@digrams, substr($word, $_, 2)) for 0 .. length($word)-1;
>    $digrams[-1] .= '$';
>    return \@digrams;
> }
>
> I'm not so sure about this being perl's forte.  There was no way to
> use regular expressions here :-)
>
> I would actually like to see some methods that interact more with the
> Zope environment.
>
> Regards,
> Gisle
>
> _______________________________________________
> Zope-perl maillist  -  Zope-perl@zope.org
> http://lists.zope.org/mailman/listinfo/zope-perl
>