Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

everyauction script error bidding errors

by simonwilliams (Initiate)
on Jun 21, 2005 at 20:58 UTC ( [id://468813]=perlquestion: print w/replies, xml ) Need Help??

simonwilliams has asked for the wisdom of the Perl Monks concerning the following question:

Hi thankyou in advance if you can help me, I have this script below and there is a problem. The script shows all items over 1 bid so thats 2nd bid, in the bidding on items regardless to the "$alias" connections with the item for sale. Ive beleive its somthing to do with this section which is the part that works out if you are a bidder but not the highest bidder;

if ($#bids) { for (my $i = $#bids; $i > 1; $i = 1) { my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_b +id($bids[$i]); $time = sort ({ int $a <=> int $b } $time); my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bid +s[$#bids]); if (($form{'ALIAS'} ne $lastbid[0]) && ($time < $lastbid[3])) { print qq| <TR><TD ALIGN=CENTER width=15%><A HREF=$ENV{'SCRIPT_NAME'}\?cat +egory=$key\&item=$file><font size=2 color=red>$file</font></font></A> <br><A HREF=$ENV{'SCRIPT_NAME'}\?action=watchitems&ALIAS=$form{ +'ALIAS'}&CATEGORY=$key&WATCH=$file><font size=1 color=red>Watch This! +</font></a></TD> <TD ALIGN=CENTER width=42%><A HREF=$ENV{'SCRIPT_NAME'}\?categor +y=$key\&item=$file><font size=2 color=red>$title</font></A> </TD><TD ALIGN=CENTER width=10%><font size=2>$timeremain</font> +</TD> <TD ALIGN=CENTER width=10%><font size=2 color=red>$#bids</font> +</TD><TD ALIGN=CENTER width=13%><font size=2 color=red>OUTBID\!<BR>\$ +$lastbid[2]</font></TD>\n|; }} }

My values are correct and its showing the items that the user has got the high bid of correct. To break it down a little more i suspect this section is core to the problem;
if ($#bids) { for (my $i = $#bids; $i > 1; $i = 1) { my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_b +id($bids[$i]); $time = sort ({ int $a <=> int $b } $time); my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bid +s[$#bids]); if (($form{'ALIAS'} ne $lastbid[0]) && ($time < $lastbid[3])) {
Any advice will help Thankyou

######################################################### sub bidding { print "<p><TABLE BORDER=1 WIDTH=90% cellspacing=2 align=center> +\n"; print "<TR><TD ALIGN=CENTER COLSPAN=5><FONT SIZE=3><b>Items I'm + Bidding On</b></font></TD></TR>"; print "<TR><TD ALIGN=CENTER width=10% bgcolor=#E5E5E5><font siz +e=2>Item \#</font></TD><TD ALIGN=CENTER width=40% bgcolor=#E5E5E5><fo +nt size=2>Title</font></TD><TD ALIGN=CENTER width=20% bgcolor=#E5E5E5 +><font size=2>Closes</font></TD><TD ALIGN=CENTER width=10% bgcolor=#E +5E5E5><font size=2>Bids</font></TD><TD ALIGN=CENTER width=10% bgcolor +=#E5E5E5><font size=2>Current Bid</font></TD></TR>\n"; my $totalbuy; my $total_items = 0; my $total_bids = 0; my $gooditem; foreach my $key (sort keys %category) { opendir (THEDIR, "$config{'basepath'}$key") || &oops("Category +directory $key could not be opened."); my @allfiles = grep( -T, map{"$config{'basepath'}$key/$_"} sort + { int $a <=> int $b } readdir THEDIR ); closedir THEDIR; FILE: foreach my $file (@allfiles) { $file =~ s/^$config{'basepath'}$key\///; $file =~ s/\.dat$//; my ($title, $reserve, $inc, $desc, $image, $grabber, $catfeat, +$galfeat, $buyit, $bold, $dutch, $qty, $ship, $shipcost, $shipto, $pa +y0, $pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, @bids) = +&read_item_file($key,$file); if ($title ne '') { $form{'ALIAS'} = ucfirst(lc($form{'ALIAS'})); my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_b +id($bids[0]); my @firstbid = &read_bid($bids[0]); my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_b +id($bids[$#bids]); my @lastbid = &read_bid($bids[$#bids]); my @closetime = localtime($file); $closetime[4]++; my $timeremain = time_remain($file); my $willbuy = $bid if (($form{'ALIAS'} eq $lastbid[0]) && ($for +m{'ALIAS'} ne $firstbid[0]) && ($bid eq $lastbid[2]) && ($reserve == +0) || ($form{'ALIAS'} eq $lastbid[0]) && ($form{'ALIAS'} ne $firstbid +[0]) && ($bid eq $lastbid[2]) && ($reserve > 0) && ($bid >= $reserve) +); $totalbuy=($totalbuy + $willbuy); $totalbuy = &priceformat ($totalbuy); $total_items = ($total_items + ($title ne '')) if (($form{'ALIA +S'} eq $lastbid[0]) && ($form{'ALIAS'} ne $firstbid[0]) && ($bid eq $ +lastbid[2]) || ($form{'ALIAS'} eq $lastbid[0]) && ($form{'ALIAS'} ne +$firstbid[0]) && ($bid eq $lastbid[2]) && ($bid >= $reserve)); $total_bids = ($total_bids + ($#bids > 0)) if (($form{'ALIAS'} +eq $lastbid[0]) && ($form{'ALIAS'} ne $firstbid[0]) && ($bid eq $last +bid[2])); $gooditem = ($bid => $reserve) if (($form{'ALIAS'} eq $lastbid[ +0]) && ($form{'ALIAS'} ne $firstbid[0]) && ($bid eq $lastbid[2]) && ( +$reserve > 0) && ($bid => $reserve)); if (($form{'ALIAS'} ne $firstbid[0]) && ($form{'ALIAS'} eq $alias) +) { print "<TR><TD ALIGN=CENTER width=15%><A HREF=$ENV{'SCRIPT_NAME +'}\?category=$key\&item=$file><font size=2 color=green><b>$file</b></ +font></A>"; print "<br><A HREF=$ENV{'SCRIPT_NAME'}\?action=watchitems&ALIAS +=$form{'ALIAS'}&CATEGORY=$key&WATCH=$file><font size=1 color=red>Watc +h This!</font></a></TD>"; print "<TD ALIGN=CENTER width=42%><A HREF=$ENV{'SCRIPT_NAME'}\? +category=$key\&item=$file><font size=2 color=green><b>$title</b></fon +t></A>"; print "</TD><TD ALIGN=CENTER width=10%><font size=2>$timeremain +</font></TD>"; print "<TD ALIGN=CENTER width=10%><font size=2 color=green><b>$ +#bids</b></font></TD><TD ALIGN=CENTER width=13%><font size=2 color=gr +een><b>\$$lastbid[2]</b></font></TD>\n" if (($bid eq $lastbid[2]) && +($reserve == 0) && ($#bids > 0)); print "<TD ALIGN=CENTER width=10%><font size=2 color=green><b>$ +#bids</b></font></TD><TD ALIGN=CENTER width=13%><font size=2 color=gr +een><b>\$$lastbid[2]</b></font><br><font size=1 color=red>Reserve Not + Met</font></TD>\n" if (($bid eq $lastbid[2]) && ($reserve > 0) && ($ +bid < $reserve)); print "<TD ALIGN=CENTER width=10%><font size=2 color=green><b>$ +#bids</b></font></TD><TD ALIGN=CENTER width=13%><font size=2 color=gr +een><b>\$$lastbid[2]</b></font><br><font size=1 color=green>Reserve M +et</font></TD>\n" if (($bid eq $lastbid[2]) && ($reserve > 0) && ($bi +d >= $reserve)); } if ($#bids) { for (my $i = $#bids; $i > 1; $i = 1) { my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_b +id($bids[$i]); $time = sort ({ int $a <=> int $b } $time); my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bid +s[$#bids]); if (($form{'ALIAS'} ne $lastbid[0]) && ($time < $lastbid[3])) { print qq| <TR><TD ALIGN=CENTER width=15%><A HREF=$ENV{'SCRIPT_NAME'}\?cat +egory=$key\&item=$file><font size=2 color=red>$file</font></font></A> <br><A HREF=$ENV{'SCRIPT_NAME'}\?action=watchitems&ALIAS=$form{ +'ALIAS'}&CATEGORY=$key&WATCH=$file><font size=1 color=red>Watch This! +</font></a></TD> <TD ALIGN=CENTER width=42%><A HREF=$ENV{'SCRIPT_NAME'}\?categor +y=$key\&item=$file><font size=2 color=red>$title</font></A> </TD><TD ALIGN=CENTER width=10%><font size=2>$timeremain</font> +</TD> <TD ALIGN=CENTER width=10%><font size=2 color=red>$#bids</font> +</TD><TD ALIGN=CENTER width=13%><font size=2 color=red>OUTBID\!<BR>\$ +$lastbid[2]</font></TD>\n|; }} }} }} if ($totalbuy == 0) { print "<TR><TD ALIGN=CENTER><FONT SIZE=3 COLOR=red>$total_items +</FONT></TD><TD ALIGN=CENTER></TD><TD ALIGN=CENTER></TD><TD ALIGN=CEN +TER><FONT SIZE=3 COLOR=red>$total_bids</FONT></TD>"; print "<TD ALIGN=CENTER><FONT SIZE=3 COLOR=red>$config{'currenc +y'}$totalbuy</FONT></TD></TR>"; } if ($totalbuy > 0) { print "<TR><TD ALIGN=CENTER COLSPAN=5><FONT SIZE=3>Total Curren +t Successful Bids</FONT></TD></TR>"; print "<TR><TD ALIGN=CENTER><FONT SIZE=3 COLOR=GREEN>$total_ite +ms</FONT></TD><TD ALIGN=CENTER></TD><TD ALIGN=CENTER></TD><TD ALIGN=C +ENTER><FONT SIZE=3 COLOR=GREEN>$total_bids</FONT></TD>"; print "<TD ALIGN=CENTER><FONT SIZE=3 COLOR=GREEN>$config{'curre +ncy'}$totalbuy</FONT></TD></TR>"; } print "</TABLE><br>"; }

READMORE tags added by Arunbear

Replies are listed 'Best First'.
Re: everyauction script error bidding errors
by mkmcconn (Chaplain) on Jun 21, 2005 at 21:57 UTC
    simonwilliams, you wrote,
    if($#bids){ for (my $i = $#bids; $i > 1; $i = 1) { ... } }
    Where I'm pretty sure that what you meant was,
    if (@bids > 1){ for (my $i = 0; $i <= $#bids; $i++) { ... } }
    But, many of us would prefer to write this as:
    if (@bids > 1){ for my $bid (@bids){ my ($alias, $email, $bid, $time, $add1, $add2, $add3) = readbid($b +id); } }
    You also wrote,
    $time = sort ({ int $a <=> int $b } $time);

    This will not do anything. $time is not a LIST. See perldoc -f sort;

    By the way, you'll get better answers if you work harder on distilling your question to one essential issue. Hope all this helps, and welcome to the Monastery.
    mkmcconn

      If i replace the code with this;
      my $lowest_new_bid; if ($#bids) { for (my $i=1; $i<scalar(@bids); $i++) { my ($alias, $email, $bid, $time, $add1, $add2, $add3, $oqty, $sold +qty) = &read_bid($bids[$i]); if (($form{'ALIAS'} ne $lastbid[0]) && ($form{'ALIAS'} eq $alias)) + { if (($form{'ALIAS'} ne $firstbid[0]) && ($form{'ALIAS'} eq $alias) +) {
      it works but it now prints all the bids the user has placed on the item and i need it to only display the highest last placed bid but under the current high bid of the highest bidder.

        simonwilliams,

        1.    if ($#bids){...}
          does what you mean, but it doesn't really say what you mean. For that, you should say
             if (@bids > 1){ ... };
          i.e., if @bids contains more bids than one, then ...
        2.   for (my $i=1; $i<scalar(@bids); $i++) { ... }
          could be written ...
            for (my $i=1; $i < @bids; $i++) { ... }
          ... without any change in meaning. @bids is being evaluated in a scalar context. No need to say scalar() explicitly.
        3. Let me oversimplify your problem, and you can build on that. You want to choose the highest bid, excluding your own from consideration (always the first bid), and print only the highest bid.
          my $highest; if (@bids > 1){ for (my $i = 1; $i < @bids; $i++) { my ($alias, $email, $bid, $time, $add1, $add2, $add3, $oqty, $soldqty) = read_bid($bids[$i]); $highest = $bid > $highest ? $bid : $highest; } print "Highest bid: $highest\n"; }

        mkmcconn
Re: everyauction script error bidding errors
by eyepopslikeamosquito (Archbishop) on Jun 21, 2005 at 21:23 UTC

    for (my $i = $#bids; $i > 1; $i = 1) { my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_b +id($bids[$i]); $time = sort ({ int $a <=> int $b } $time);
    The above code makes no sense to me. In the first line above, the $i = 1 at the end of the for loop makes the "loop" pointless because it processes at most one element, namely the last item in the array. In the last line above, sorting a scalar is similarly pointless because you are sorting just one item.

    I am assuming you are very new to Perl. I suggest you start by reading the book Learning Perl and having a look around learn.perl.org.

    Oh, and always start your scripts with:

    use strict;

      Is this section the problem because what it is im trying to do is;
      my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bid +s[0]);
      This section reads bid number 0 which in my case is the seller in my .dat files so bid 1 would be the first bidder. I need the script to read each individual bid however many there may be i.e 1 to 22 and pick out if the member who is logged in as form{'ALIAS'} has placed a bid which has been outbid. By using this code i can manualy enter the bidders bid in order however this is no good i need somthing to automatically do this;
      my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_bid($bid +s[1]); ----- what ever number the bidder is
      which i thought this section did;
      for (my $i = $#bids; $i > 1; $i = 1) { my ($alias, $email, $bid, $time, $add1, $add2, $add3) = &read_b +id($bids[$i]); $time = sort ({ int $a <=> int $b } $time);

        Try ...

        if (@bids > 1){ for my $bid (1..$#bids){ my ($alias, $email, $bid, $time, $add1, $add2, $add3) = read_bid($ +bids[$bid]); } }

        As noted elsewhere, your sort on a scalar will not do what you are trying to do, since sort() works on a LIST.
        mkmcconn
        edit: fix artifacts in code copied from elsewhere.

Re: everyauction script error bidding errors
by Transient (Hermit) on Jun 21, 2005 at 21:11 UTC
    is this the same thing as eAuction?

    I'm not quite sure what the problem is or else I'd help. Good luck!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://468813]
Approved by moot
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2024-03-28 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found