On Wed, Oct 03, 2001 at 01:05:26PM +0200, Bart Lateur wrote:
> But I really really doubt if there's any computer language in the world
> that uses underscores in their keywords.
                                 ^^^^^^^^

OH!  Then I *did* explain it badly!

These >>>are not keywords!<<< They're not even magic built-in methods.
They're perfectly ordinary, user-defined methods and functions.
That's the real beauty of it.  It lets any function act as an
iterator.

Perhaps it's because I've been using file examples so much.  Ok, I'll
pick something else...

Here is *literally* how you might write a function which reads a web
page, finds the links and then you get only the ones that are mp3s.

    use LWP::Simple;
    sub eachlink {      # Happy?  No underscores. :P
        my(@urls) = @_;

        # Since it isn't really the point to rewrite the guts of
        # HTML::LinkExtor, I'll do it the really cheesy way.
        foreach my $url (@urls) {
            my $html = get $url;

            while( $html =~ /(http://\S+)/g ) {
                local $_ = $1;
                yield;
            }
        }
    }

The payoff is in how you use that function:

    eachlink(@urls) {
        print "Oooh, musack!" if /\.mp3$/;
    }

This is not only for function calls (as the & prototype is).  It would
work on method calls just the same:

    HTML::Link.eachlink(@urls) {
        print "Oooh, musack!" if /\.mp3$/;
    }

Compare that interface with the current interface to HTML::LinkExtor
and you might get an idea of it's usefulness.


-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <[EMAIL PROTECTED]>       Kwalitee Is Job One
Death follows me like a wee followey thing.
        -- Quakeman

Reply via email to