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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pattern matching and hyperlinks

Status
Not open for further replies.

jay123454

Programmer
Jun 15, 2001
46
US
i will have an html document with patterns such as this

6.3.2.1 T_THI
7.3.2.3 G_G
5.2.3.3 S_SH

but many of them...and they refer to a definition later in the doc and i'd like to link them together..so i need a program to reference the letter combination with the corresponding number..then set a source at the location above and a target at the definition later in the
document.....

just to be clear..i'll use another example. it would be like making a source link on the T_THI 6.3.2.1, in many cases more than one, whereever T_THI occurs...and then making the 6.3.2.1 a target in the definitions section....i may split up the docs into two sections so i can write two separate programs if this will help....please let me know if anyone has any ideas or questions..thanks!
 
to make a successful regex to split that up, it's necessary to know EXACTLY how the data is formatted. is it exactly like you posted it? you sort of hinted at it not being exactly that way further down into your post, so i wasn't sure... "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
yes..it's exactly as i posted

such as:

1.2.3.4 T_THEY
2.3.4.5 W_WHY

 
*note - the set of data you just gave is not exactly the same as the one you first gave - there is more whitespace inbetween the fields in the second one.

well, anyway, i'm going to assume you've already read in the file as an array. if you're having problems here, ask for more help.
next, you're going to want to narrow down that array to just those elements that look like the ones above. from there, you'll want to make a hash out of the data by splitting is up into it's two pieces. here's how that'll look:[tt]
#@file should already exist
my %hash;
foreach my $line (@file)
{
if (chomp($line) =~ m~^(\d+\.\d+\.\d+\.\d+)\s+(\w+)$~)
{
$hash($1) = $2;
}
}
[/tt]
the resulting %hash will have the numbers as the keys and the letters as the value - you access them like this:
print $hash{'1.2.3.4'};
would print out "T_THEY"

from here, i was never really too sure on what you wanted done with this data - that is, what sort of link you need made. give an example of how the data should be transformed into the link, and it'll be easier to show you what to do. "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top