Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: DBI converting hex values

by samtregar (Abbot)
on Nov 02, 2006 at 18:35 UTC ( [id://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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2025-06-18 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.