Your skill will accomplishwhat the force of many cannot PerlMonks

### Re: DBI converting hex values

by samtregar (Abbot)
 on Nov 02, 2006 at 18:35 UTC ( #581943=note: print w/replies, xml ) Need Help??

in reply to DBI converting hex values

If you can't convince DBI to leave your hex value alone you can always convert it back:

```  \$a = "Paul";
\$a =~ s!(.)!sprintf("%02x", ord(\$1))!eg;
print "0x\$a";

I'm sure there's a more clever way to do that with unpack, but I'm way too lazy to figure it out!

-sam

Replies are listed 'Best First'.
Re^2: DBI converting hex values
by shmem (Chancellor) on Nov 02, 2006 at 18:52 UTC
From Saints in our Book: "..and remember there are a lot of things monks are supposed to be but lazy is not one of them" :-)
```perl -le ' print "0x",unpack "H*",pack "A*","Paul"'
0x5061756c

--shmem

```_(\$_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
/\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.(\$e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;\$e.e && print}```

You might want to be more lazy and skip the pack "A*". (:

- tye

Darn, you're right... do { print ((my \$hubris = \$hubris) >>= 1)} for \$this_one :-)

--shmem

Re^2: DBI converting hex values
by Sprad (Hermit) on Nov 02, 2006 at 18:58 UTC
The problem, though, is that this DBI call is part of a larger module that encapsulates DB access for some tools. It's another layer on top of DBI. My layer doesn't know which items were formerly hex and which were strings all along, so I can't blindly convert.

I could convert, though, if there were a way to know what data I was getting back. That might be another way to tackle the problem, but I'm not sure how to do that either. All I've done so far is just hand back the result array, which works great for everything except these fields.

---
A fair fight is a sign of poor planning.

Create A New User
Node Status?
node history
Node Type: note [id://581943]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2017-08-17 13:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (288 votes). Check out past polls.

Notices?