in reply to Extracting info from URL into an array
use strict; use warnings; use URI; use File::Basename; my @suffix = qw(.jsp .html .asp .htm); for (</path/to/test1/*.txt>) { open (FH,$_); my $uri = URI->new(<FH>); close FH; next unless $uri->scheme; my %q = $uri->query_form; my (undef,@key) = split( /\//, dirname($q{content}) ); push @key, basename($q{content},@suffix); print "<Textfile>\n", "filename: {", basename($_), "}\n", "Keys: {", join(',',@key), "}\n", "</Textfile>\n", ; }
use strict; use warnings; use URI::Find; use File::Basename; # add more if needed my @suffix = qw(.jsp .html .asp .htm); # optionally open a file here and replace DATA # with the name of the filehandle you opened my $data = do {local $/;<DATA>}; my $finder = URI::Find->new(\&call_back); $finder->find(\$data); sub call_back { my $uri = shift; my %q = $uri->query_form; my $content = $q{content}; # using split like this is a hack ... improvements anyone? my (undef,@key) = split(/\//,dirname($content)); # this will add the file name minus its extension push @key, basename($content,@suffix); # you could push these to an array instead of printing print "Filename: {", basename($content), "}\n"; print "Keys: {", join(',',@key), "}\n\n"; } __DATA__ http://www.yyy.com/store/application/meraqf?origin=rrr.jsp&event=link( +goto)&content=/asp/administrative/catalog/products/Network/benefits.j +sp is this text automatically 'ignored'? yes, it is ;) http://foo.com/?content=/asp/management/catalog/products/Network/propa +ganda.asp http://foo.com/?content=/path/to/bar.html
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (jeffa) Re: Extracting info from URL into an array
by Anonymous Monk on May 27, 2003 at 15:07 UTC |