473,396 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Odd Perl bitwise-AND & MySQL problem?

Here's one for some bored problem solver :)

I ran across this earlier today and fixed it, but don't exactly know
why. (that usually only happens in C :)

I'm using Perl version 5.8.0 btw.

Ok, let's start here: I end up with an array that comes from a
fetchrow_array() call to MySQL. I return the array to a function.

Ok, then the function does this (roughly):

sub func()
{
my @dat = shift;

my $val = $dat[3] & $dat[4] & $dat[5] & 0x7fff;

print $val;
}

In the MySQL database, element 0 = int, 1 = varchar(32), 2 =
varchar(255), 3 = int, 4 = int, 5 = int, 6 = int, etc..

Ok, so I call the function. Let's assume $dat[3] = 57 (0x39), $dat[4]
= 2045 (0x7fd), $dat[5] = 2047 (0x7ff).

Guess what I get for output? --> "00" (I should get 57 (0x39) btw)

Not just a zero "0" but _2_ zeros. So, clearly it thinks something
stringy is there. But why? I guess that is my question.

Now, if I populate @dat myself (i.e. don't get the values from MySQL
calls) it works fine.

To my knowledge only numbers are in the 3 variables and I've tested
this. If I print the values individually, they print correctly. I
also do a 'length' on them and I get 2, 4, and 4 respectively -- which
is correct.

How did I fix it?

my $val = int($dat[3]) & int($dat[4]) & int($dat[5]) & 0x7fff;

I added int()s around each value. So apparently Perl thought there
was something before the numbers in the variables?? Nothing should be
there but numbers, the values come from table elements that are ints
and are read right into a Perl array. Aside from a bug, I can't see
how this could get corrupted or how I could be missing something.

I've done quite a bit of MySQL/Perl programming and I've never had
this happen before, in fact, this specific problem doesn't happen all
the time even in this code. Only with when returning data from
specific rows (in my case), though it is consistent and reproducable
-- it's not flaky. I can note that $dat[2] (which comes from a
varchar(255)) contains some text and some "/r/n" characters. The ones
that don't fail don't contain "/r/n" characters in $dat[2]. I don't
know if this is related, I only have 3 rows of data (at the moment)
and 1 causes the problem.

I'm thinking this is a problem in the Perl MySQL DBI module? I
realize I can do more troubleshooting to narrow it down a bit better
and I probably will tonight, but just wanted to get it out there and
see what people thought. Maybe this has been seen before?
Jul 19 '05 #1
0 2195

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: Christopher Benson-Manica | last post by:
I'm trying to compute the absolute value of an integer using only bitwise operators... int x; sscanf( "%d", &x ); printf( "%d\n", (x^((~((x>>31)&1))+1)) + ((x>>31)&1) ); That works, but it...
12
by: sandy_pt_in | last post by:
How to mulitply two integer numbers using bitwise operators in C language.Please reply as early as possible
8
by: Mantorok Redgormor | last post by:
The only adder I was able to come up with for incrementing by one, uses a for loop. I was trying to do this without using a for loop while emulating i++(it's for obfuscated code) Anyone know...
8
by: Paul E Collins | last post by:
Suppose I have a few Keys objects: Keys k1 = Keys.V; // V Keys k2 = Keys.Control | Keys.V; // Ctrl+V Keys k3 = Keys.Shift | Keys.J; // Shift+J I need to determine which of these include the...
2
by: Aamir Mahmood | last post by:
hi how can i perform a bitwise NOT on a int or long or uint type variable? so that the bits should be inverted in the result. - aamir
2
by: Random | last post by:
I need to apply a filterparameter to a result set in my GridView based on the selection in a DropDownList control. I want to use the integer SelectedValue property of the DropDownList to filter...
10
by: Emilio | last post by:
Do I use 'or' for bitwise operations where in c# I use | ?
6
by: Fredrik Melin | last post by:
Hi, Is there any easy way to split a bitwise value, for sample 127 to an array into 1, 2, 4, 8, 16, 32, 64? Regards Fredrik Melin
6
by: Ramtin Kazemi | last post by:
Hi How can i perform bitwise rotation in C#?
16
by: Santhosh | last post by:
Hi to all, How the individual digits of a number can be obtained using the bitwise operators alone.Is it possible to do it ? If we have n = 34 Result has to be 3,4. Thanks a billion for...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.