Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: golf anyone? (hexdump)

by MrNobo1024 (Hermit)
on Aug 09, 2002 at 03:35 UTC ( #188818=note: print w/replies, xml ) Need Help??

in reply to golf anyone? (hexdump)

16 bytes: (not exact right output format) printf'%v2X',pop
34 bytes: $_=sprintf'%v2X',pop;y/. / 0/;print


Replies are listed 'Best First'.
Re^2: Hexdump (Golf)
by tadman (Prior) on Aug 09, 2002 at 08:04 UTC
    Nothing like an opportunity to improve:
    That's 19 characters by my count. Using the internal equivalent of space, plus why pop when you can just fire it in and hope for the best?

    Am I correct in assuming the function has to return the string instead of printing it? One character either way.

    I also think this only works in Perl 5.6 or better. A test in 5.005_02 fails, printing %*vX In that case, I think a 33 character solution is:
    $_=unpack"H*",pop;s/..\B/$& /g;$_
    As a note, I would have used @_ in the second one, but under an older version, it would seem that the unpack function is prototyped and this array is rendered to hex 31, which is in fact an ASCII "1". This could save one stroke, for a total of 32.

    I do like jmcnamara's innovative solution.
Re: Re: golf anyone? (hexdump)
by djantzen (Priest) on Aug 09, 2002 at 03:47 UTC

    Nice MrNobo. You can reach a compromise in length between your two approaches using:

    printf '%*vX', ' ', pop;

      Wow, thanks guys. I learned something useful here.

      I knew about %v, or thought I did: I didn't realize it was a modifier, or that I could change the dot to the space!

      So (reading the perlfunc docs) what is the meaning of the V modifier? I don't understand the explaination "interpret integer as Perl's standard integer type"


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2018-05-25 09:44 GMT
Find Nodes?
    Voting Booth?