in reply to Re: Breaking a Loop
in thread Breaking a Loop
now, what i want, is where it says#!/usr/local/bin/perl # Author: Dipul Patel # This Perl Script takes a home site chosen by the user, then calcula +tes # the distance from that home site to every site in the system and pr +ints # in a HTML table. #--------------------------------------------------------------------- # Process information for main site #--------------------------------------------------------------------- $lat_long = "/tmp/sitesLL"; $filepath = "/data1/PHL/neighbors"; $query_string = $ENV{'QUERY_STRING'}; @search = split(/&/,$query_string); @info = split(/=/, $search[0]); @siteinfo = split(/-/, $info[1]); print "Content-type: text/html\n\n"; #read in lat and long file open(LL, $lat_long); @lat_long = <LL>; close(LL); #Get long,lat,g,h,j for main site @dataline = grep /^$siteinfo[0]/, @lat_long; @dataparse = split(/\|/, $dataline[0]); ($sitelat, $sitelong) = split(/,/, $dataparse[3]); $g = $dataparse[4]; $h = $dataparse[5]; $j = $dataparse[6]; #--------------------------------------------------------------------- # Process information for every other site, one at a time #--------------------------------------------------------------------- #open directory and get sites names opendir DIR, $filepath; @allfiles = grep !/^\.\.?$/, readdir DIR; closedir DIR; @allfiles = sort @allfiles; $totalsite=@allfiles; @allfiles2=@allfiles; foreach $site(@allfiles) { chomp $site; @frst = split(/[a-z][a-z]/, $site); @cell = split(/[A-Z]/, $frst[1]); push(@othersiteinfo, $cell[0]); } #Open assiociated neighbor list file open(IN, "$filepath/$siteinfo[1]"); @data=<IN>; close(IN); #get sector numbers for neighbors foreach $line(@data){ #chomp $line; @information = split (/\|/, $line); push (@neighbor,$information[1]); } $n=-1; $temphigh = 0; while($n<$totalsite){ $n++; @dataline2 = grep /^$othersiteinfo[$n]/, @lat_long; @dataparse2 = split(/\|/, $dataline2[0]); ($sitelat2, $sitelong2) = split(/,/, $dataparse2[3]); $g2 = $dataparse2[4]; $h2 = $dataparse2[5]; $j2 = $dataparse2[6]; #--------------------------------------------------------------------- # calculate distance from main site to other sites #--------------------------------------------------------------------- $a=($g2-$g)*($g2-$g); $b=($h2-$h)*($h2-$h); $c=($j2-$j)*($j2-$j); $abc=($a+$b+$c); $sqabc=sqrt($abc); $distance=(3960*$sqabc); $distance = sprintf "%1.2f", $distance; $distance2=$distance; $distance3=$distance; $distance4=$distance; if ($temphighval >= $temphigh){ $temphigh=$temphighval; } if ( $distance > 10){ next; } # if ( $distance == 0){ # next; # } # The following code, first compares the sector number of the current + site to that of the neighbor list, # then it complies 2 arrays, one with all the neighbors, the other ar +ray with the other sites. $element = $othersiteinfo[$n]; if (grep {$_ eq $element} @neighbor) { @array3=($allfiles[$n],$distance2); push (@test1, @array3); push (@highval, $distance2); } else{ @array2=($allfiles[$n],$distance); push (@test2, @array2); } }#end whileloop my $done_sort=0; # or some more meaningful name while( $cond) { # probably some code here unless( $done_sort) { sort_the_array( @array); $done_sort=1; } # more code here } #create hash and sorted array for non-neighbors %distance=@test2; @sorted = sort { $distance{$a} <=> $distance{$b} } keys %distance; #extract sector numbers from sitename for use in hyperlinks. $k=0; @nonneighsect=@sorted; for ($h=0; $h<=$#nonneighsect; $h++) { $nonneighsect[$h] =~ s/\w{2}(\d{4})\w+/$1/; } #create hash and sorted array for neighbors %distance2=@test1; @sorted2 = sort { $distance2{$a} <=> $distance2{$b} } keys %distan +ce2; #extract sector numbers from sitename for use in hyperlinks. $j=0; @neighsect=@sorted2; for ($i=0; $i<=$#neighsect; $i++) { $neighsect[$i] =~ s/\w{2}(\d{4})\w+/$1/; } #-------------------- # the following code prints a table, with all the sites sorted first b +y neighbor, then distance. It also provides links # to automattically calculate distances for other sites, as well as ma +p them. #-------------------- print "<HTML>\n"; print "<HEAD><TITLE>Distance Tool</TITLE></HEAD>\n"; print "<TABLE BORDER=1 cellspacing=1 cellpadding=1 WIDTH =65%>\n"; print "<TR><TH Colspan = 4> Distance From $siteinfo[1] To:<TH>"; # print " <FONT SIZE=\-5><A HREF=\"http://www-mat.nextel.com/cg +i-bin/rfn-cgi/neighbormap2.cgi?frames=frames&site=$siteinfo[0]-$sitei +nfo[1]&rpt=Daily-Total&Lfactor=150000§or=1\" target=_top>1</a></f +ont>\n"; # print " <FONT SIZE=\-5><A HREF=\"http://www-mat.nextel.com/cg +i-bin/rfn-cgi/neighbormap2.cgi?frames=frames&site=$siteinfo[0]-$sitei +nfo[1]&rpt=Daily-Total&Lfactor=150000§or=2\" target=_top>2</a></f +ont>\n"; # print " <FONT SIZE=\-5><A HREF=\"http://www-mat.nextel.com/cg +i-bin/rfn-cgi/neighbormap2.cgi?frames=frames&site=$siteinfo[0]-$sitei +nfo[1]&rpt=Daily-Total&Lfactor=150000§or=3\" target=_top>3</a></f +ont>\n"; print "<FONT SIZE =\-5>"; print "<TR><TH>Site<TH>Distance<TH>Neighbor<TH>Map(sector)\n"; foreach $site3 (@sorted2) { print " <TR><TD><FONT SIZE=\-5><A HREF=\"http://www-mat.ne +xtel.com/cgi-bin/rfn-cgi/distance.cgi?site=$neighsect[$j]-$site3\" >$ +site3<TD>$distance2{$site3}<TD align=center>YES</font>\n"; print " <TD align=center><FONT SIZE=\-5><A HREF=\"http://w +ww-mat.nextel.com/cgi-bin/rfn-cgi/neighbormap2.cgi?frames=frames&site +=$neighsect[$j]-$site3&rpt=Daily-Total&Lfactor=150000§or=1\" targ +et=_top>1</a></font>\n"; print " <FONT SIZE=\-5><A HREF=\"http://www-mat.nextel.com +/cgi-bin/rfn-cgi/neighbormap2.cgi?frames=frames&site=$neighsect[$j]-$ +site3&rpt=Daily-Total&Lfactor=150000§or=2\" target=_top>2</a></fo +nt>\n"; print " <FONT SIZE=\-5><A HREF=\"http://www-mat.nextel.com +/cgi-bin/rfn-cgi/neighbormap2.cgi?frames=frames&site=$neighsect[$j]-$ +site3&rpt=Daily-Total&Lfactor=150000§or=3\" target=_top>3</a></fo +nt>\n"; $j++; } foreach $site2 (@sorted) { print " <TR><TD><FONT SIZE=\-5><A HREF=\"http://www-mat.ne +xtel.com/cgi-bin/rfn-cgi/distance.cgi?site=$nonneighsect[$k]-$site2\" +>$site2<TD>$distance{$site2}<TD align=center>NO</font>\n"; print " <TD align=center><FONT SIZE=\-5><A HREF=\"http://w +ww-mat.nextel.com/cgi-bin/rfn-cgi/neighbormap2.cgi?frames=frames&site +=$nonneighsect[$k]-$site2&rpt=Daily-Total&Lfactor=150000§or=1\" t +arget=_top>1</a></font>\n"; print " <FONT SIZE=\-5><A HREF=\"http://www-mat.nextel.com +/cgi-bin/rfn-cgi/neighbormap2.cgi?frames=frames&site=$nonneighsect[$k +]-$site2&rpt=Daily-Total&Lfactor=150000§or=2\" target=_top>2</a>< +/font>\n"; print " <FONT SIZE=\-5><A HREF=\"http://www-mat.nextel.com +/cgi-bin/rfn-cgi/neighbormap2.cgi?frames=frames&site=$nonneighsect[$k +]-$site2&rpt=Daily-Total&Lfactor=150000§or=3\" target=_top>3</a>< +/font>\n"; $k++; } print "</FONT>"; print "</TABLE>\n"; print "</HTML>\n";
i want the 10 to be replaced with the highest value of the array defined at the end of the loop:if ( $distance > 10){ next; }
But.. that array is added to everytime the loop runs, and i need the highest value from it when it is complete, so i can specify the largest distance to map. I hope this helps.if (grep {$_ eq $element} @neighbor) { @array3=($allfiles[$n],$distance2); push (@test1, @array3); push (@highval, $distance2); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: Re: Breaking a Loop
by Adam (Vicar) on Oct 10, 2000 at 22:59 UTC | |
by Anonymous Monk on Oct 10, 2000 at 23:18 UTC | |
by merlyn (Sage) on Oct 10, 2000 at 23:33 UTC | |
|
RE: RE: Re: Breaking a Loop
by Anonymous Monk on Oct 10, 2000 at 23:31 UTC | |
by Ovid (Cardinal) on Oct 11, 2000 at 01:26 UTC |