I hear perl is the way to go for string parsing, so here is the test!

I have a file like this:

...
<li><a href="DSC_9866.JPG"> DSC_9866.JPG</a></li>
<li><a href="DSC_9867.JPG"> DSC_9867.JPG</a></li>
...

and I want to get a list of the file names. That is, the result I want is a list of strings

DSC_9866.JPG, DSC_9867.JPG, etc

How would I go about this?

Thanks,

Dave

Yep, I messed up. I have already flagged the post as "bad" and am just awaiting a mod to move it.

Sorry!

For really simple html you can use regular expressions. For more complex data it would be better to search CPAN for a good html parser module and learn how to use it (which I haven't got around to doing yet). Meanwhile the following script should do what you want.

#!/usr/bin/perl
#ParseList.pl
use strict;
use warnings;
open my $fh, '<', '/home/david/Programming/Perl/data/list.txt';
my @list;
while (<$fh>){
    m/href="(\w+\.\w+)"/;
    push @list, $1;
}
print "Here is the list:\n";
print join(", ", @list);

Edited 6 Years Ago by d5e5: n/a

This question has already been answered. Start a new discussion instead.