<?xml version="1.0" encoding="windows-1252"?>
<node id="363198" title="SirBones's scratchpad" created="2004-06-10 17:04:25" updated="2005-06-29 03:32:34">
<type id="182711">
scratchpad</type>
<author id="362844">
SirBones</author>
<data>
<field name="doctext">
&lt;hr&gt;
&lt;p&gt;
/me sighs.
&lt;p&gt;
My company has an online form for ordering replacement cabinet keys.  I put in the key number, and under quantity, I put 3.
A week or so later, I received 1 key.
&lt;p&gt;
So I went back to the form and put in the key number, and quantity = 2.
&lt;p&gt;
I received 1 key.
&lt;p&gt;
So I went back again and put in quantity = 1.
&lt;p&gt;
I received 1.
&lt;p&gt;
&lt;c&gt;$n&gt;1 ? $n = $n-($n-1) : $n = 1;&lt;/c&gt;
&lt;hr&gt;
&lt;p&gt;
A discussion on coverting a hex string to a signed int...
&lt;pre&gt;
planetscape chuckles SirBones++
[ChemBoy]: when I do the same operation on x86, it comes out as you say. For 
unsigned numbers there's a good shortcut for this problem but not for signed, 
so you just insert reverse between the pack and the unpack.
[ChemBoy]: making the total line perl -le'$str = "0001";print unpack "s", reverse pack "H4",$str'
[tye]: that code depends on the endianness (in case that wasn't clear)
[SirBones]: Excellent! Works!
[ChemBoy]: sorry about the extra steps, I clearly need to recaffeinate
SirBones is near tears. It's sick how long I've spent on this bug.
[ChemBoy]: Yeah, if you ever distribute that code, you will probably want to do 
a little check to make sure your byte-order is correct before you run that line. 
Or I and the other SGI/Mac users of the world will hunt you down and smack you on 
the big end. ;-)
planetscape offers up the gnawed bones of her victims if that would make SirBones 
feel better...
SirBones appreciates the gesture, but is too tired to eat.
[ChemBoy]: That is to say: use Config; my $packed = pack "H4", $str; 
if ('4321' eq $Config{byteorder}) { $packed = reverse $packed; } 
print unpack "s", $packed;)
[planetscape]: maybe a wee hug would do instead... the dragon furls her wings 
'round SirBones and gives a gentle squeeze...
&lt;/pre&gt;
&lt;hr&gt;
&lt;br /&gt;[id://368391]
&lt;br /&gt;[id://341265]
&lt;br /&gt;[id://358176]
&lt;br /&gt;[id://430901]
&lt;br /&gt;[id://479716]
&lt;br /&gt;[id://118343]
&lt;br /&gt;[id://505817]
&lt;br /&gt;[id://498434]
&lt;br /&gt;[id://510524]
&lt;br /&gt;[id://513869]
&lt;br /&gt;[id://4677]
&lt;br /&gt;[id://518170]
&lt;br /&gt;[id://111481]
&lt;br /&gt;[id://420989]
&lt;br /&gt;[id://264423]
&lt;br /&gt;[id://535643]
&lt;br /&gt;[id://577181]
&lt;br /&gt;[id://233432]
&lt;br /&gt;[id://441777]
&lt;br /&gt;[id://471075]
&lt;br /&gt;[id://585964]
&lt;br /&gt;[id://586942]
&lt;br /&gt;[id://549385]
&lt;br /&gt;[id://549385]</field>
</data>
</node>
