Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

link array 1

Status
Not open for further replies.

Oostwijk

Technical User
Oct 19, 2003
82
0
0
NL
I've got an array which has multiple lines like these in it:
<A HREF=" Page</A><BR>
<A HREF=" Page</A><BR>

As you can see it are links to certain websites.
Now I want to do stuff with each link within the array.

foreach $value (@X){
print "..$value..";
}

With these lines I want to get each link and do something with it. Though $value contains all links instead one at a time. How can I adjust my code so that $value contains one link per time ?
 
sounds to me like you would want to split() then string up.

how is the array defined?
 
The script reads in the lines from a file on my hdd, and stores a part of that file in the array. The lines stored in the array all look like this:
<A HREF=" Page</A><BR>
<A HREF=" Page</A><BR>
and so on.

This is my script:

#!/usr/local/bin/perl
use CGI;
use LWP::Simple;
$q=new CGI;
print "Content-type: text/html\n\n";

$linkje="c:\links.txt";

$winkel="../file.txt";
getstore($linkje,$winkel);
$eerstewoordklein="<!--Start of Links-->";


$tweedewoord="<BR><CENTER>";
open SAMPLE,"../file.txt" or warn $!;

@X = (join'',<SAMPLE>) =~ /($eerstewoordklein.*?$tweedewoord)/gs;
chomp @X;
close SAMPLE;


s/\d\d-\d\d|\(thanks.*?\)(?=<br)//ig for @X;

foreach $value (@X){
print $value;
}

Please note: I know I can read in files on the hdd easier than that, when the script is finished it must read a file from a certain website, so that's why I used LWP::Simple
 
Hi,

As jad says you could use a split to parse your links ...

here is a quick but very crude example which will only ever work if your links are formatted in the same way as above.

(@links) = split (/\<BR\>/,$array[$element]);

# where $array[$element] contains links you require
# assumptions made based on code provided
# i.e. each link is 'separated' by a line break <BR>
# this does not remove the <a href tags either !

foreach (@links)
{ print "<BR>$links[$_]"; }

this may get you started temporarily
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top