PDA

View Full Version : How much can a variable will hold?


zenweezil
05-09-2003, 09:52 PM
Here's the deal.

I am opening a database grabbing matching content and trying to make the listing become one variable so I can simply use that varible elsewhere instead of the entire database query.

The problem I am running into is the variable is only grabbing the first line of the listing instead of the entire listing. Do you need a different type of varible for it to contain the entire $LIST { $listing }.

Here is what I am doing (I will skip to right where I am trying to save the listing):

$LIST{ $taglinekey } = sprintf( "%s%s%s%s",
"<li><a href=\"$link\">$headline<BR>\n" );
}
}

# Sort the found listings by price ( ascending )
foreach $listing ( sort { $b <=> $a }( keys( %LIST ) ) ) {
# Read listing into output buffer
$relatedstories = $LIST{ $listing };
}
close( DATA );

Then later in the same cgi I call the $relatedstories variable:

print DATA $relatedstories

And the result is only the first line of the listing instead of the entire listing.

Thanks in advance.

YUPAPA
05-10-2003, 07:17 AM
Are you talking about a text based database?

If it is a text-file database, can I see the format?

Are you trying to save the headline into hash and print it out? Cos at the end, I see you are trying to print to a file...

My english sux, so sorry it takes me a lot of time to understand~ :o

Mouldy_Goat
05-11-2003, 01:07 AM
Hi zenweezil, I think the main problem you are having is that here:
foreach $listing ( sort { $b <=> $a }( keys( %LIST ) ) ) {
# Read listing into output buffer
$relatedstories = $LIST{ $listing };
}

It's just looping through and replacing the $relatedstories every time with the value of $LIST{ $listing } until it reaches the last value in the list.

To be honest I'm not sure you need to put it into another variable at all (even though it probably does look nicer later). You can do it in one line with something like this:
print DATA "$list{$_}\n" foreach ( sort { $a <=> $b } keys %list );

Hope that helps a bit.
(P.S. - $b <=> $a is descending price order, so $relatedstories would've held the least expensive item.)

zenweezil
05-12-2003, 12:10 PM
Ah-ha.

I was so wrapped up into it only being one item from the listing I didn't even realize I was just looping different data into the variable.

Thanks - I think I can get it from here.