"There was no template for the script but I can recommend checking to see if the file is lost when it gets put in the hash table or if it gets lost in the sort. In perl there are three types of variables variants, arrays, and hash tables represented by these characters $, @, % respectively. In the script I used two hash tables (%variableName) to organize the way the home flite’s would be displayed. I would recommend you run tests on a machine with apache installed and test the script to see where the file is getting lost by Outputting the contents of the hash tables to the screen. Without seeing everything though I would have to recommend looking at the html file first."
But he is no longer able to work on the page...
Also, I'm unfamiliar with apache. How do I begin testing scripts?
"...you're really going to need some help from a programmer..."
But you will have to give us some clues...
You indicated
"...I can't see any errors in the scripting..."but then again your ex-programmer suggested a few things
"...recommend checking to see if the file is lost when it gets put in the hash table or if it gets lost in the sort ... test the script to see where the file is getting lost by Outputting the contents of the hash tables to the screen..."What were the results of the tests, or don't you know how to do what he was asking?
Shawn
PS Not sure I'd agree that "...Sorting is a big pain in the neck in Perl...". Perl provides better support for sorting than most languages. It has the built-in 'sort' function. Couple taht with with perl's regex functionality, and you're on a winner where sorting is concerned. And if that isn't enough, there are lots of library out there too. In any language, algorithms for sorting huge amounts of data very efficiently can be complex, but that 'sort' of problem (pardon the pun) is unlikely to come up in run-of-the-mill web development. When it does come up, another language may be chosen instead of perl, but not because perl falls short in it 'sort' functionality. Rather because the problem will require a compiled language with more sophisticated data structures instead of a scripted one like perl or php.
P.S. Perl seems like a good language, but I'm just not advanced enough yet to make sense of my problem. (Logically I do, but when it comes to actually fixing it, I'm in the dark.)
For example:
%hash = ('one' => 1, 'two' => 2, 'three' => 3);
This would make $hash{'one'} output 1, $hash{'two'} output 2 and so on. Now let's take it further.
$hash{'four'} = 4;
$hash{'five'} = 5;
$hash{'three'} = 6;
Now what you would have is 1,2,6,4,5 as values in the hash.
I know this is a simplistic example, but this could be the problem.
Scott Geiger
@priceRange = split /-/, $contents{'priceRange'};
$low = $priceRange[0];
if ( $priceRange[1] eq "+" )
{
$priceRange[1] = 100000000;
}
$high = $priceRange[1];
$i = 0;
opendir(BIG, "../homeflite/");
@filenames = grep(/\.html$/,readdir(BIG));
closedir(BIG);
foreach $file (@filenames)
{
$fileContents{$file} = get( "http://www.stuff.com/homeflite/" . $file );
&setPrice;
$SortPrice{$tmpPrice} = $file;
}
foreach $key (sort keys %SortPrice)
{
push @sortedFiles, $SortPrice{$key};
}
$last = shift @sortedFiles;
push @sortedFiles, $last;
foreach $file (@sortedFiles)
{
$contents = $fileContents{$file};
$imageFile = substr($file, 0, index($file, ".") );
&getMetaVariables;
if ( $#price <= 1 )
{
$price = $price[0] * 1000;
$price += $price[1];
}
elsif ( $#price == 2 )
{
$price = $price[0] * 1000000;
$price += $price[1] * 1000;
$price += $price[2];
}
if ( $price >= $priceRange[0] && $price <= $priceRange[1] )
{
&outputHTML;
}
elsif ( $contents{'priceRange'} eq "all" )
{
&outputHTML;
}
}
print "</center>\n";
print "</td>\n";
print "</tr>\n";
print "</table>\n";
print end_html;
sub setPrice()
{
chomp($fileContents{$file});
@testHTML = split /\n/, $fileContents{$file};
$tmp = substr( $testHTML[2], index($testHTML[2], chr(34) ) + 1, length($testHTML[2]) );
$tmp = substr( $tmp, 0, index($tmp, chr(34) ) );
@data = split /-/, $tmp;
@tmpRice = split /,/, $data[5];
if ( $#tmpRice <= 1 )
{
$tmpPrice = $tmpRice[0] * 1000;
$tmpPrice += $tmpRice[1];
}
elsif ( $#tmpRice == 2 )
{
$tmpPrice = $tmpRice[0] * 1000000;
$tmpPrice += $tmpRice[1] * 1000;
$tmpPrice += $tmpRice[2];
}
}
sub getMetaVariables()
{
chomp($contents);
@testHTML = split /\n/, $contents;
$tmp = substr( $testHTML[2], index($testHTML[2], chr(34) ) + 1, length($testHTML[2]) );
$tmp = substr( $tmp, 0, index($tmp, chr(34) ) );
@data = split /-/, $tmp;
@price = split /,/, $data[5];
}
________________________________________________________
&setPrice;
$SortPrice{$tmpPrice} = $file;
What if you have 2 files with the same $tmpPrice. The second data set will over-write the first based on this.
e.g.:
file_a has a $tmpPrice = 200000
file_b has a $tmpPrice = 250000
file_c has a $tmpPrice = 200000
then where $tmpPrice = 200000; $sortPrice{$tmpPrice} = file_c. file_a is over-written.
Scott Geiger
foreach $file (@filenames)
{
$fileContents{$file} = get( "http://www.stuff.com/homeflite/" . $file );
&setPrice;
$SortPrice{$tmpPrice} = $file;
}foreach $key (sort keys %SortPrice)
{
push @sortedFiles, $SortPrice{$key};
}
to:
foreach $file (@filenames)
{
$fileContents{$file} = get( "http://www.stuff.com/homeflite/" . $file );
&setPrice;
$SortPrice{$file} = $tmpPrice;
}my @sorted = sort {
$SortPrice{$a} <=> $SortPrice{$b}
} keys %SortPrice;foreach $key (@sorted)
{
push @sortedFiles, $key;
}
is what causes the first entry to be pushed to the last entry, but I need it to be displayed first. How do I rewrite that line to display the first entry first? I've tried altering the line a little bit, but I haven't had any luck...
Please help!
To help further it would be helpful to have further information, such as the contents of the SortPrice hash, and any other debugging results.
Shawn
That code worked but now the sorting is screwed up
and the very first entry (at the cheapest price) is being displayed last, after the most expensive house. How do I fix that?
I have no idea why your programmer did it, but here is the problem:
$last = shift @sortedFiles;
push @sortedFiles, $last;
you can try to comment this two line out.