Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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!


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


    _($_=" "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 :-)


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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://581943]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2018-06-23 01:46 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.