PDA

View Full Version : a little perl help, please


donger
10-15-2005, 08:10 PM
Hi,
I'm working on fixing the bisonbison converter so that it works with the new absolute hand history format. Right now, everything is working except you have to reorder the seat numbers numerically before pasting in the hand:

Seat 6 - DAWGNWNUTS69 ($196 in chips)
Seat 7 - JERKSTORE ($181.50 in chips)
Seat 9 - NEOND ($104 in chips)
Seat 5 - STANSFIELD ($49 in chips)

has to become:

Seat 5 - STANSFIELD ($49 in chips)
Seat 6 - DAWGNWNUTS69 ($196 in chips)
Seat 7 - JERKSTORE ($181.50 in chips)
Seat 9 - NEOND ($104 in chips)

in order for the converter to work.

I was wondering if someone could help me write the piece of code to sort this $Players object by the PlayerSeatNumber property?

Here's the relevant code where the object is filled:

<font class="small">Code:</font><hr /><pre>
while ($Message =~ s/Seat (\d+) - (.*?) \(((\$)?\d+(\.\d+)?) in chips\)//)
{
$Players{"$j"}-&gt;{"PlayerSeatNumber"} = $1;
$Players{"$j"}-&gt;{"PlayerName"} = $2;
$Players{"$j"}-&gt;{"PlayerStack"} = $3;

###SORT $Players here so the following code doesn't break

#name the seats, starting at the button
if ($Players{"$j"}-&gt;{"PlayerSeatNumber"} == $SeatButton)
{
$Players{"$j"}-&gt;{"PlayerTitle"} = "Button";
$Players{"$j"}-&gt;{"PlayerTitleDisplay"} = "Button";
}
elsif (($Players{"$j"}-&gt;{"PlayerSeatNumber"} &gt; $SeatButton) &amp;&amp; ($j &lt;= $PlayerCount))
{
$Players{"$j"}-&gt;{"PlayerTitle"} = pop @SeatTitleList;
$Players{"$j"}-&gt;{"PlayerTitleDisplay"} = pop @SeatTitleDisplayList;

}
$j++;
}
</pre><hr />



THANKS!
donger

jba
10-17-2005, 09:15 AM
why are you sorting in the middle of that loop? I'm not really sure what you're getting at but you can sort @Players with something like:

@sorted = sort { $a-&gt;{"PlayerSeatNumber"} &lt;=&gt; $b-&gt;{"PlayerSeatNumber"} } @Players

SheridanCat
10-17-2005, 01:13 PM
I tried working with the original code and found it very, very difficult and prone to breakage and utter confusion. It's pretty terrible stuff. If you're planning to submit a patch to bisonbison to handle Absolute properly, I wish you luck.

I decided to just reimplement a converter for kicks. If you're interested, you can find the latest here:

http://www.pokergeek.com/software

It doesn't currently support Absolute, but adding that support is fairly trivial.

Anyway....

I'm a little puzzled by the code snippet. Perhaps a little more context for the code would be helpful. Specifically, where is $j coming from? If you're actually trying to sort %Players within that while loop while populating %Players, something is wrong with the logic.

If the j$ scalar is just a counter, which it might be based on the $j++ at the end, then I would suggest you use the seat number ($1) as the hash key instead. In that case you can just use "foreach my $key ( sort keys %Players )" for simple sorting.

Good luck,

T

zram21
10-17-2005, 01:33 PM
[ QUOTE ]
In that case you can just use "foreach my $key ( sort keys %Players )" for simple sorting.

[/ QUOTE ]

That won't work on a 10 seat table. (I can't remember if Absolute is 9 handed or 10 handed tables.) That will produce a sorted list of 1,10,2,3,4,5,6,7,8,9.

for (sort { $a &lt;=&gt; $b } keys %Players) would do what he was looking for though.

SheridanCat
10-17-2005, 02:18 PM
[ QUOTE ]
[ QUOTE ]
In that case you can just use "foreach my $key ( sort keys %Players )" for simple sorting.

[/ QUOTE ]

That won't work on a 10 seat table. (I can't remember if Absolute is 9 handed or 10 handed tables.) That will produce a sorted list of 1,10,2,3,4,5,6,7,8,9.

for (sort { $a &lt;=&gt; $b } keys %Players) would do what he was looking for though.

[/ QUOTE ]

Oh, yeah, forgot about that wrinkle. The default sort is to sort them as strings.

T