Re: [Hampshire] extracting phrases from a file.

Page principale

Répondre à ce message
Auteur: Vic
Date:  
À: hampshire
Sujet: Re: [Hampshire] extracting phrases from a file.

> You can probably do this quite easily in perl.


You can.

> Are there any nice short programs to do this?


Something like this?

#! /usr/bin/perl

my $fname = $ARGV[0];
die "need a filename" unless defined ($fname);

open INFILE, "<$fname" or die "Can't open $fname for reading";

while (<INFILE>)
{
    my @links = $_ =~ m|<a +href="([^"]+)"|gc;
    if(scalar(@links) > 0)
    {
        foreach my $link (@links)
        {
            # Do something here
            print "Link : $link\n";
        }
    }
}


You could probably write this in a much more compact fashion if you wanted.

Vic.