Re: decimal - Binary

2011-11-18 Thread Aristotle Pagaltzis
* Ronald J Kimball rjk-perl-...@tamias.net [2011-11-16 21:50]: It is greedy, but the important thing to remember is that the regular expression engine will find the longest *leftmost* match. To put that a third way: the engine will match at the first possible location, and will make the match

Re: decimal - Binary

2011-11-16 Thread Georg Moritz
Greetings Sandro all, From the keyboard of Sandro CAZZANIGA [16.11.11,14:26]: hi! Just a little JAPH for convert decimal to binary Feel free to comment it ;) golfed down a bit, just for fun... #!/usr/bin/perl -l @ARGV or die No args; print$_: ,($_=unpackB*,packN,$_)=~s/0+//?$_:$_

Re: decimal - Binary

2011-11-16 Thread John Douglas Porter
What's the point? Seems to me the only purpose of this code beyond the obvious unpack(B*,pack(N, $arg)) line is to reformat the result into an odd, probably application-dependent format. --- On Wed, 11/16/11, Sandro CAZZANIGA cazzaniga.san...@gmail.com wrote: From: Sandro CAZZANIGA

Re: decimal - Binary

2011-11-16 Thread Olof Johansson
On 2011-11-16 09:57 -0500, Ronald J Kimball wrote: That should be s/0*//, otherwise you'll get the wrong result for numbers above 2147483647. That should be s/^0*//, otherwise you'll get the wrong result for numbers above 2147483647. Also: printf$_:%b\n,$_ for@ARGV --

Re: decimal - Binary

2011-11-16 Thread Ronald J Kimball
On Wed, Nov 16, 2011 at 04:14:57PM +0100, Olof Johansson wrote: On 2011-11-16 09:57 -0500, Ronald J Kimball wrote: That should be s/0*//, otherwise you'll get the wrong result for numbers above 2147483647. That should be s/^0*//, otherwise you'll get the wrong result for numbers above

Re: decimal - Binary

2011-11-16 Thread Daniel Cutter
Hasn't anyone noticed that a decimal to binary or whatever conversion isn't a JAPH by definition, alone because it does anything other than output the JAPH? With a looser definition it must at least output Just another Perl hacker, perhaps on stderr Daniel Cutter @_=($_=aaceeehhjklnoprrrsttu,

Re: decimal - Binary

2011-11-16 Thread Olof Johansson
On 2011-11-16 11:57 -0500, Ronald J Kimball wrote: No, you are wrong. s/0*// is sufficient, because /0*/ will always match at the start of the string anyway. You're clearly an expert. I yield. Can you open a bug report with perl and getting this fixed? --

Re: decimal - Binary

2011-11-16 Thread Ronald J Kimball
On Wed, Nov 16, 2011 at 07:49:14PM +0100, Olof Johansson wrote: On 2011-11-16 11:57 -0500, Ronald J Kimball wrote: No, you are wrong. s/0*// is sufficient, because /0*/ will always match at the start of the string anyway. You're clearly an expert. I yield. Can you open a bug report with

Re: decimal - Binary

2011-11-16 Thread Georg Moritz
From the keyboard of Ronald J Kimball [16.11.11,14:14]: On Wed, Nov 16, 2011 at 07:49:14PM +0100, Olof Johansson wrote: On 2011-11-16 11:57 -0500, Ronald J Kimball wrote: No, you are wrong. s/0*// is sufficient, because /0*/ will always match at the start of the string anyway. rye

Re: decimal - Binary

2011-11-16 Thread Olof Johansson
On 2011-11-16 14:14 -0500, Ronald J Kimball wrote: It's working as expected for me, so I'm not sure what needs to be fixed. Hum, now I'm ashamed. Sorry. But why is that not greedy? (I got other results earlier, but I can't reproduce now so I have probably made an error in my earlier attempts.)

Re: decimal - Binary

2011-11-16 Thread John Douglas Porter
Olof Johansson o...@ethup.se wrote: But why is that not greedy? Remember, the *first* match wins, even if it's shorter than a possible later match. ISTR that some have argued that's a bug. Well, too bad. It's too late. :-) -- john many jars porter

Re: decimal - Binary

2011-11-16 Thread Ronald J Kimball
On Wed, Nov 16, 2011 at 09:34:58PM +0100, Olof Johansson wrote: On 2011-11-16 14:14 -0500, Ronald J Kimball wrote: It's working as expected for me, so I'm not sure what needs to be fixed. Hum, now I'm ashamed. Sorry. But why is that not greedy? (I got other results earlier, but I can't