in reply to Checking links between web-pages

You needn't repetitively scan if you store a map inside a hash structure.:
#like this... #Set up the link-map; my %linkmap; my @pages = glob(*.cfm); foreach $page (@pages) { @links_to = find_links($page); #your sub for (@links_to) { $linkmap{$page}{$_} = undef; } } #print out what links to each file foreach $page (@pages) { print "What links to $page: ".join(';',what_links_to($page)); } # sub to find what links to something sub what_links_to { my $dest = shift; #i.e. 'a.cfm' for what links to 'a.cfm' my @links_to; for (keys %linkmap) { next if ($_ eq 'a.cfm'); #skip what 'a.cfm' links to push (@links_to, $_) if exists $linkmap{$_}{'a.cfm'}; } return @links_to; }

So you only scan the files once, and then check the hash repeatedly. Much faster.

radiantmatrix
require General::Disclaimer;

Replies are listed 'Best First'.
Re^2: Checking links between web-pages
by yacoubean (Scribe) on Oct 13, 2004 at 16:42 UTC
    Yes, this is a very good idea. I was actually thinking a hash would be good, but I've been afraid to try it because I have yet to use hashes and they kind of scare me. ;)
    But I think I'll use this oportunity to break into them.