Re: fun with hashes!

2007-11-24 Thread Vladi Belperchinov-Shabanski
On Sat, 24 Nov 2007 10:43:58 +0100
David Landgren <[EMAIL PROTECTED]> wrote:

> Uri Guttman writes:
> >>>>>> "AP" == A Pagaltzis <[EMAIL PROTECTED]> writes:
> > 
> >   AP> * Jerrad Pierce <[EMAIL PROTECTED]> [2007-11-23 22:50]:
> >   >> exists( $dispatch{$sub} ) ? $dispatch{$sub}->() :
> >   >> warn "Key <$sub> does not exist in the dispatch table";
> > 
> >   AP> ( $dispatch{$sub} || sub { warn "no such action '$sub'" } )->();
> > 
> > some variations on that:
> > 
> > my $sub = $dispatch{$key} or die "trying to call missing code" ;
> > $sub->() ;
> > 
> > or:
> 
> [...]
> 
> > or:
> > 
> > my $sub = $dispatch{ $key } || $dispatch{ 'default' } ;
> 
> 
> Why stop there? Assuming $key never evaluates to 0:
> 
>my $sub = $dispatch{ $key || 'default' };

usual case would be there is no value (coderef) for the key, not empty key!

> 
> If it does, wait until 5.10 comes out and:
> 
>my $sub = $dispatch{ $key // 'default' };
> 
> Although there really is little point stuffing the coderef into a 

little? really? I'd rather handle situation when $sub is empty.
shuldn't happen or get logged (debug obviously) for example.

> scalar, it's not like there's anything you can do to it. It's clearer to 
> not draw attention to it and just run the damned thing:
> 
>$dispatch{ $key || 'default' }->();
> 

Which still may trigger "Can't use string ("") as a subroutine ref while 
"strict refs" in use at ..."

:)

> David
> 


-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
http://cade.datamax.bg/   pgp/gpg key id: 6F35B214 (pgp.mit.edu)
--
equally destructive as we are, don't you think we've also gone too far?!


pgpZRpQuqgczo.pgp
Description: PGP signature


Re: fun with hashes!

2007-11-23 Thread Vladi Belperchinov-Shabanski
On Fri, 23 Nov 2007 23:18:20 +0100
"A. Pagaltzis" <[EMAIL PROTECTED]> wrote:

> * Jerrad Pierce <[EMAIL PROTECTED]> [2007-11-23 22:50]:
> > exists( $dispatch{$sub} ) ? $dispatch{$sub}->() :
> >  warn "Key <$sub> does not exist in the dispatch table";
> 
> ( $dispatch{$sub} || sub { warn "no such action '$sub'" } )->();
> 

or  &{ ... || ... }->()

just to avoid problems like:

  print ( $dispatch{$sub} || sub { warn  } )->();


-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
http://cade.datamax.bg/   pgp/gpg key id: 6F35B214 (pgp.mit.edu)
--
equally destructive as we are, don't you think we've also gone too far?!


Re: Unknown level of hash

2005-03-28 Thread Vladi Belperchinov-Shabanski

two solutions:

obvious one:

   @a = ( 'E1', 'E2', 'E3', 'En' );
   eval '$a{ ' . join( ' }{ ', @a ) . '} = 1';
   print Dumper( \%a );

Interpreters rule :)

and 'hidden loop' one:

   @a = ( 'E1', 'E2', 'E3', 'En' );
   $a = 1;
   map{ $a = { $_ => $a } } reverse @a;
   print Dumper( $a );

both print this:

$VAR1 = {
  'E1' => {
'E2' => {
  'E3' => {
'En' => 1
  }
}
  }
};

cheers!

P! Vladi.

On Mon, 28 Mar 2005 15:06:41 -0800
"Zhuang Li" <[EMAIL PROTECTED]> wrote:

> Hi, given an array: @a = ('E1', 'E2', ..., 'En'); 
> 
>  
> 
> Is there an easy way, hopefully one liner, to do the following without a
> loop? If not, will Perl support this in Perl 6?
> 
>  
> 
> $hash->{E1}->{E2}->...->{En} = 1;
> 
>  
> 
>  
> 
> Thanks,
> 
>  
> 
> john
> 
> 


-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
http://cade.datamax.bg/   pgp/gpg key id: 6F35B214 (pgp.mit.edu)
Cross the ocean deep, wake now from your sleep
Kiss the past goodbye, don't follow empty skies...



pgp13Hzk2Nl3I.pgp
Description: PGP signature


Re: "Secret" operators

2005-02-02 Thread Vladi Belperchinov-Shabanski
On Wed, 2 Feb 2005 12:33:35 +1100 (EST)
Andrew Savige <[EMAIL PROTECTED]> wrote:

> Jos_ Castro wrote:
> > Apart from the "secret eskimo greeting" and the "goatse operator",
> > can anyone tell me about other "secret" operators?
> 
> Let's not forget the Ton Hospel "high-precedence decrement"
> operator ~- invented during a golf tournament (anyone remember
> which one?).
> 
> IIRC, Ton's ~- invention allows you to eliminate the parens in:
> 
> $y = ($x-1)*4;
> 
> by using instead:
> 
> $y = ~-$x*4;
> 
> saving a whopping two strokes. This trick should work on any
> twos complement machine -- and I'm not aware of any perl running
> on any non twos complement machine.

will not work if $x < 0

> 
> /-\
> 
> 
> Find local movie times and trailers on Yahoo! Movies.
> http://au.movies.yahoo.com
> 


-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://cade.datamax.bg/
DataMax SA   http://www.datamax.bg
there is still one truth on which we can depend
we've started something we can never end


pgpXeOAMawvJG.pgp
Description: PGP signature


Re: "Secret" operators

2005-02-01 Thread Vladi Belperchinov-Shabanski
On Tue, 1 Feb 2005 11:49:57 +
Jos_ Castro <[EMAIL PROTECTED]> wrote:

> Hi, guys.
> 
> Apart from the "secret eskimo greeting" and the "goatse operator", can
> anyone tell me about other "secret" operators?
> 
> Examples:
> 
> eskimo:   }{
> goatse:   =()=
> 
> eskimo usage:   perl -ne '}{print $.'

   perl -MO=Deparse -ne 'print $.'

has this actual code:

   LINE: while (defined($_ = )) {
   print $.;
   }

on the other hand your example:


   perl -MO=Deparse -ne '}{print $.' 

actually is:


   LINE: while (defined($_ = )) {
   ();
   }
   {
   print $.;
   }

the trick is that you can have loop and finish code:

   perl ' loop-code-here }{ finish-code-here'

> goatse usage:   perl -e '$_="zbrughau";$b=()=/u/g;print $b'

   $b = () = /u/g;

is the same as:

   @a = /u/g;
   $b = @a;

i.e. () forces array context (actually it is array), then returns element count 
in $b

no big secrets here, though I never thought of such () use. thanks for the hint 
:))

-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://cade.datamax.bg/
DataMax SA   http://www.datamax.bg
there is still one truth on which we can depend
we've started something we can never end


Re: "Secret" operators

2005-02-01 Thread Vladi Belperchinov-Shabanski
On Tue, 1 Feb 2005 15:57:33 +0100
[EMAIL PROTECTED] (Philippe 'BooK' Bruhat) wrote:

> 
> There's also @{[]} but I don't know f it has a name.
> 
> Usage: print "splatt @{[ ... ]} pow"
> where ... is any valid expression, and the result list is join()ed with $"
> (space).

[] construct reference to anonymous array, @{} dereferences the array ref. 
finally the array is interpolated inside string.

it is equal to:

  @a = ( 1, 2, 3 );
  print "splatt @a pow";

the only use is to force array context inside string:

  %a = ( 1, 2, 3 );
  print "splatt @{[%a]} pow";
  
but don't think it is usefull (except obfuscation bonus:))

--
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://cade.datamax.bg/
DataMax SA   http://www.datamax.bg
there is still one truth on which we can depend
we've started something we can never end


Re: P2P in 15 lines

2004-12-16 Thread Vladi Belperchinov-Shabanski

list please? :)

only IO::Socket::INET I guess...

On Wed, 15 Dec 2004 22:58:07 -0800
Brad Greenlee <[EMAIL PROTECTED]> wrote:

> Sorry, forgot to mention that I worked under the assumption that if I 
> used any modules, they had to be part of the standard Perl distribution. 
> The only thing that's really lacking compared to the python version is 
> some kind of digest algorithm to avoid sending the password over the wire.
> 
> -b
> 
> 


-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://cade.datamax.bg/
DataMax SA   http://www.datamax.bg
there is still one truth on which we can depend
we've started something we can never end


pgpG98x0q6evr.pgp
Description: PGP signature


Re: P2P in 15 lines

2004-12-15 Thread Vladi Belperchinov-Shabanski

On Wed, 15 Dec 2004 16:59:35 +0100
Sven Neuhaus <[EMAIL PROTECTED]> wrote:

> Can we beat them (in perl)?
> http://www.freedom-to-tinker.com/tinyp2p.html

I believe this is not fun :) Using libraries etc ruins the golf scent unless
strict description. However without investigating the tinyp2p which lacks
description what it exactly does, I came up with those:

# pps.pl server--returns file name and data by regexp from current dir
#!/usr/bin/perl
use IO::Socket::INET;
use IO::All;
my $sr=$sock = IO::Socket::INET->new(Listen=> 5,
 LocalAddr => 'localhost:',
 ReuseAddr => 1 );
while(4)
  {
  my $cl = $sr->accept() or next;
  $re = <$cl>;
  chop($re);
  my @f = grep /$re/, <*>;
  my $n = shift @f; 
  my $d < io $n;
  print $cl "$n\n";
  print $cl $d;
  }
# 400 bytes approx.

and

# ppc.pl client--requests file by regexp and save under the server-offered name
#!/usr/bin/perl
use IO::Socket::INET;
use IO::All;

my $cl = IO::Socket::INET->new(  PeerAddr => "$ARGV[0]:") or die "connect 
error\n";

$| = 1;
print $cl "$ARGV[1]\n";
$n = <$cl>;
chop($n);
$/=undef;
<$cl> > io $n;
# 200 bytes approx.


both are *FAR* from perfect, there are so many issues like security, 
redirection etc. but 
still a shot into plain client/server httpd direction :)))

P! Vladi.
-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://cade.datamax.bg/
DataMax SA   http://www.datamax.bg
there is still one truth on which we can depend
we've started something we can never end


pps.pl
Description: Binary data


ppc.pl
Description: Binary data


pgpFxQsdUlqfI.pgp
Description: PGP signature


Re: P2P in 15 lines

2004-12-15 Thread Vladi Belperchinov-Shabanski

On Wed, 15 Dec 2004 16:59:35 +0100
Sven Neuhaus <[EMAIL PROTECTED]> wrote:

> Can we beat them (in perl)?
> http://www.freedom-to-tinker.com/tinyp2p.html

I believe this is not fun :) Using libraries etc ruins the golf scent unless
strict description. However without investigating the tinyp2p which lacks
description what it exactly does, I came up with those:

# pps.pl server--returns file name and data by regexp from current dir
#!/usr/bin/perl
use IO::Socket::INET;
use IO::All;
my $sr=$sock = IO::Socket::INET->new(Listen=> 5,
 LocalAddr => 'localhost:',
 ReuseAddr => 1 );
while(4)
  {
  my $cl = $sr->accept() or next;
  $re = <$cl>;
  chop($re);
  my @f = grep /$re/, <*>;
  my $n = shift @f; 
  my $d < io $n;
  print $cl "$n\n";
  print $cl $d;
  }
# 400 bytes approx.

and

# ppc.pl client--requests file by regexp and save under the server-offered name
#!/usr/bin/perl
use IO::Socket::INET;
use IO::All;

my $cl = IO::Socket::INET->new(  PeerAddr => "$ARGV[0]:") or die "connect 
error\n";

$| = 1;
print $cl "$ARGV[1]\n";
$n = <$cl>;
chop($n);
$/=undef;
<$cl> > io $n;
# 200 bytes approx.


both are *FAR* from perfect, there are so many issues like security, 
redirection etc. but 
still a shot into plain client/server httpd direction :)))

P! Vladi.
ps: sorry for duplicates, wrong account :/
-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://cade.datamax.bg/
DataMax SA   http://www.datamax.bg
there is still one truth on which we can depend
we've started something we can never end


pps.pl
Description: Binary data


ppc.pl
Description: Binary data


pgp6nYBeH39n6.pgp
Description: PGP signature


Re: Dynamically creating a hash for keys()

2004-10-19 Thread Vladi Belperchinov-Shabanski
On Tue, 19 Oct 2004 16:10:01 -0500
[EMAIL PROTECTED] wrote:

> 
> Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]>:
> 
> :skip values:
> :
> :%hash = qw( fred filntstone barney rubble tom delong );
> :print( map { $a=!$a ? $_ : () } reverse( %hash ) );
> :
> :perhaps not too bad map() example :)
> :
> :P! Vladi.
> 
> 
> Or, you can do it the regular old un-fun way, and just use a 
> second, temporary hash:
> 
> my %hash = qw(fred flintstone barney rubble tom delong);
> my %hsah = reverse %hash;
> print keys %hsah;
> 

yes. which is shown in at least two posts before mine...
personally I like "values %hash" most :))

-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
http://cade.datamax.bg/
Cross the ocean deep, wake now from your sleep
Kiss the past goodbye, don't follow empty skies...



pgpTtxSm3Z4yH.pgp
Description: PGP signature


Re: Dynamically creating a hash for keys()

2004-10-19 Thread Vladi Belperchinov-Shabanski

skip values:

%hash = qw( fred filntstone barney rubble tom delong );
print( map { $a=!$a ? $_ : () } reverse( %hash ) );

perhaps not too bad map() example :)

P! Vladi.

On Tue, 19 Oct 2004 09:50:39 -0400
Jason Foster <[EMAIL PROTECTED]> wrote:

> Can anyone help me to understand why this code refuses to compile?  
> Even better, can anyone help fix it :)
> 
>  %hash = qw( fred filntstone barney rubble tom delong );
>  print( keys( reverse( %hash ) ) );
> 
> The error message...
> 
>  Type of arg 1 to keys must be hash (not reverse) at ./killme.pl 
> line 4, near ") ) "
> 
> ... was pretty confusing since it implies that "reverse" is a type?!
> 
> I tried making an anonymous hash as follows...
> 
>  print( keys( %{ reverse( %hash ) } ) );
> 
> ... but got no results at all.
> 
> Help!
> 
> 


-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
http://cade.datamax.bg/
Cross the ocean deep, wake now from your sleep
Kiss the past goodbye, don't follow empty skies...



pgprJakZluUXS.pgp
Description: PGP signature


Re: Golf challenge: Tangled Tale

2004-06-26 Thread Vladi Belperchinov-Shabanski

sounds fine to me, I hope we can see all solutions (in one message?)
instead just the best one. now it's fun :)

good luck!

On Sat, 26 Jun 2004 13:13:55 +0200
Brad Greenlee <[EMAIL PROTECTED]> wrote:

> You're all right. My bad, but as I said, it's been a long time since 
> I've been on this list. My apologies.
> 
> We'll finish up this little contest and then leave the golfing for the 
> official site. How about 11:59pm GMT on Monday the 28th as the deadline? 
> Send your scores to me, and I'll send out one email to the list on 
> Monday morning with the leaderboard, so everyone knows where they stand, 
> and then one on Tuesday morning with the final scores. Send me your 
> solutions after Tuesday morning and I'll post them (that way I don't 
> have to disqualify myself!)
> 
> -b
> 
> Vladi Belperchinov-Shabanski wrote:
> 
> > I'd prefer to have golf contest referee. He/She will receive the solutions
> > and will announce results on fixed periods (few days I guess) or publish on
> > web site frequently...
> > 
> > I wouldn't subscribe to another mailing list (golf) just to read numbers too :)
> > 
> > On Sat, 26 Jun 2004 10:29:28 +0100
> > Tony Bowden <[EMAIL PROTECTED]> wrote:
> > 
> > 
> >>On Fri, Jun 25, 2004 at 04:56:51PM +0200, Tobias G?dderz wrote:
> >>
> >>>Okay, with the 'new rules' ;) I'm now at 163 chars.
> >>
> >>I thought the golf list was set up precisely because long threads of
> >>people doing nothing but announcing numbers was pretty far from fun for
> >>those of who aren't that interested in "playing"?
> >>
> >>Discussing the interesting approaches that let you get these numbers,
> >>yes. Chanting an ever decreasing sequence of numbers, nope.
> >>
> >>Tony
> >>
> > 
> > 
> > 
> 


-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
http://cade.datamax.bg/
Cross the ocean deep, wake now from your sleep
Kiss the past goodbye, don't follow empty skies...



pgpZxCRkPNDi5.pgp
Description: PGP signature


Re: Golf challenge: Tangled Tale

2004-06-26 Thread Vladi Belperchinov-Shabanski

I'd prefer to have golf contest referee. He/She will receive the solutions
and will announce results on fixed periods (few days I guess) or publish on
web site frequently...

I wouldn't subscribe to another mailing list (golf) just to read numbers too :)

On Sat, 26 Jun 2004 10:29:28 +0100
Tony Bowden <[EMAIL PROTECTED]> wrote:

> On Fri, Jun 25, 2004 at 04:56:51PM +0200, Tobias G?dderz wrote:
> > Okay, with the 'new rules' ;) I'm now at 163 chars.
> 
> I thought the golf list was set up precisely because long threads of
> people doing nothing but announcing numbers was pretty far from fun for
> those of who aren't that interested in "playing"?
> 
> Discussing the interesting approaches that let you get these numbers,
> yes. Chanting an ever decreasing sequence of numbers, nope.
> 
> Tony
> 


-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
http://cade.datamax.bg/
Cross the ocean deep, wake now from your sleep
Kiss the past goodbye, don't follow empty skies...



pgpu7NsMLj0D7.pgp
Description: PGP signature


Re: Golf challenge: Tangled Tale

2004-06-24 Thread Vladi Belperchinov-Shabanski

hi,

there cannot be golf competition without strict rules and input data.
I haven't seen the data at least. I'm sorry but golf takes lot of time
chasing (possibly non-existent) solution and I guess lot of people 
won't participate just to find that someone tricked them with the initial 
rules which is not much fun :)

sorry for the the off-topic.

P! Vladi.


On Mon, 21 Jun 2004 00:34:39 +0200
Brad Greenlee <[EMAIL PROTECTED]> wrote:

> [rejoining this list after a too-long absence...forgive me if by some 
> bizarre chance this or something similar has already appeared]
> 
> Hey all...
> The following has consumed most of my evening, so I thought I'd share 
> the joy. I just came across this puzzle:
>http://scottkim.com/newmedia/tangledtale.html
> 
> After realizing it was taking me too long to figure it out in my head, I 
> started using pencil & paper.  After that started taking too long, I 
> decided to just write a program to solve it. After solving it, I figured 
> the program looked too pretty, so I thought I'd scrunch it down and make 
> it unreadable to all but the people on this list. Golf anyone? My 
> opening shot is 288.
> 
> The only rule other than the ones on the puzzle site is to print out all 
> possible solutions to the puzzle, in a readable format (i.e. put some 
> spaces between your numbers).
> 
> Cheers,
> 
> Brad
> 
> 
> 


-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
http://cade.datamax.bg/
Cross the ocean deep, wake now from your sleep
Kiss the past goodbye, don't follow empty skies...



pgpDjtNZJPSpc.pgp
Description: PGP signature


Re: my if?

2003-07-01 Thread Vladi Belperchinov-Shabanski

yes I see this funny usage :) but I rather
have both behaviours (compile+runtime) merged
somehow...

looks like this only makes sense if

my $var = expr;

is allowed, and

my $var = expr if/unless cond;

forbidden... or replaced with `?:'

my $var = cond ? expr : undef

or even

my $var = cond ? expr; # invalid

:)))

anyway I got this shade of gray, thanx. :)

On Tue, 01 Jul 2003 10:40:26 -0400
"Bernie Cosell" <[EMAIL PROTECTED]> wrote:

> On 1 Jul 2003 at 17:15, Vladi Belperchinov-Shabanski wrote:
> 
> > this one:
> > 
> > use strict;
> > 
> > for(1..3)
> >   {
> >   my $id = 1 if $_ == 3;
> >   print "[$id]\n";
> >   $id = 999;
> >   }
> 
> This is just another instance of what I've posted about [on c.l.p.m] a 
> few times, "cheap static variables".  Perl's mechanism for static 
> variables is very elegant and very powerful, but is pretty syntactically 
> ugly and generally is more than you want.  So if you just do:
> 
>sub x
>{   my $staticvbl if 0 ;
> 
>}
> 
> You now have a simple static variable -- the 'my' gets compiled at 
> compile time, so you get a variable and 'use strict' is happy... BUT: 
> since the 'my' isn't *executed* at run time, you end up with the effect 
> of a static variable.
> 
> For example:
>sub x
>{   my $staticvbl if 0 ;
>$staticvbl += 1 ;
>print "$staticvbl\n" ;
>}
>x();
>x();
>x();
> 
> prints:
> 1
> 2
> 3
> 
>   /Bernie\
> 
> -- 
> Bernie Cosell     Fantasy Farm Fibers
> mailto:[EMAIL PROTECTED] Pearisburg, VA
> -->  Too many people, too few sheep  <--   
> 
> 
> 
> 


-- 

*** WARNING: PLEASE DO NOT WRITE ME AT [EMAIL PROTECTED] ***
MAIL.BG  SERVICE IS BROKEN AND DROPS OR REFUSES MESSAGES

--
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://soul.datamax.bg/~cade
DataMax SA   http://www.datamax.bg
Welcome to this crazy world, welcome to the show that never ends...


pgp0.pgp
Description: PGP signature


Re: my if?

2003-07-01 Thread Vladi Belperchinov-Shabanski
On Tue, 1 Jul 2003 10:30:34 -0400
Ronald J Kimball <[EMAIL PROTECTED]> wrote:

> On Tue, Jul 01, 2003 at 05:15:09PM +0300, Vladi Belperchinov-Shabanski wrote:
> 
> >   my $id = 1 if $_ == 3;
> 
> my has a compile time behavior and a runtime behavior.  At compile time, my
> allocates memory for the variable and adds it to the pad.  At run time, my
> resets the value of the variable.
> 
> If you put a conditional on the my statement, then the run time behavior
> does not occur when the conditional is false.  Instead of getting reset,
> the value is preserved from the previous iteration.
> 
> This was an accidental feature that is now kept for backwards
> compatibility, because some programmers have used it to create static
> variables.  It's best to avoid it, however.
> 

I was wandering around similar explanation (yet missing compile time
behaviour) but carring older values is stunning and far from obvious :)

thanx.

> 
> Ronald
> 

P! Vladi.
ps: excuse me for the accidental `reply' instead of `new' :/ :)
--
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://soul.datamax.bg/~cade
DataMax SA   http://www.datamax.bg
Welcome to this crazy world, welcome to the show that never ends...


pgp0.pgp
Description: PGP signature


my if?

2003-07-01 Thread Vladi Belperchinov-Shabanski

hi,

if we ignore the possibility that the following code could
ruin your day, it could be considered dark fun:

this one:

use strict;

for(1..3)
  {
  my $id = 1 if $_ == 3;
  print "[$id]\n";
  $id = 999;
  }

prints:

[]
[999]
[1]

why?!

`my $id' defines new var every time in the loop, so
expected output is:

[]
[]
[1]

the only explanation I see is that `my' is executed only once,
and $id most of the time is global (i.e. packaged) so `strict' is
fooled...

any ideas?

P! Vladi.
--
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://soul.datamax.bg/~cade
DataMax SA   http://www.datamax.bg
Welcome to this crazy world, welcome to the show that never ends...


pgp0.pgp
Description: PGP signature


Re: are we having fun yet?

2003-05-29 Thread Vladi Belperchinov-Shabanski
On Sat, 24 May 2003 19:24:12 -0400
"Keith C. Ivey" <[EMAIL PROTECTED]> wrote:

> Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> wrote:
> 
> > $days = 31;
> > $days-- unless $mon % 2;

yes, my mistake, this line should be:

$days-- unless ($mon + ( $mon > 7 )) % 2;

:)

> > if( $mon == 2 )
> >   {
> >   $days--;
> >   $days-- if ( $year % 4 ) or (!( $year % 100 ) and ( $year %
> >   400 )); }
> > return $d;
> 
> Are days distributed differently in the last 5 months of
> the year in the Bulgarian calendar?  That must complicate
> international communication.
> 
> -- 
> Keith C. Ivey <[EMAIL PROTECTED]>
> Washington, DC
> 
> 


-- 

*** WARNING: PLEASE DO NOT WRITE ME AT [EMAIL PROTECTED] ***
MAIL.BG  SERVICE IS BROKEN AND DROPS OR REFUSES MESSAGES

--
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://soul.datamax.bg/~cade
DataMax SA   http://www.datamax.bg
Welcome to this crazy world, welcome to the show that never ends...


pgp0.pgp
Description: PGP signature


Re: Zip/Postal codes.

2003-01-05 Thread Vladi Belperchinov-Shabanski

hi,

Bulgarian is (\d\d\d\d)

smaller zip code as number is 1000 so a bit more exact could be

([1-9]\d\d\d) but I don't think this is better :)

P! Vladi.


On Thu, 2 Jan 2003 15:29:43 +0100
Abigail <[EMAIL PROTECTED]> wrote:

> 
> For the module Regexp::Common, I'm looking for the formats of
> zip (or postal) codes of various countries. Thanks to another
> mailing list, I've the formats for the Netherlands, Britain
> and Australia. 
> 
> For the US, I have: /\d{5}(-\d{4})?/, but I don't know whether
> any digit combination is allowed - does the format allow for
> leading 0s?
> 
> For Canada, I have: /[A-Z]\d[A-Z] \d[A-Z]\d/, but does Canada
> use all 26 letters? Is there any checksum buildin?
> 
> For all other countries, I've nothing so far. Can anyone help?
> 
> 
> 
> Abigail
> 


-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
http://soul.datamax.bg/~cade
Welcome to this crazy world, welcome to the show, that never ends...





Re: Out of memory perl script

2002-11-26 Thread Vladi Belperchinov-Shabanski

seems like a bit out of topic, but... could be fun :)

On Mon, 25 Nov 2002 15:52:21 -0800
Jacob Schroeder <[EMAIL PROTECTED]> wrote:

> I'm new to perl but I've been working on a script that will parse a large
> amount of text and while it's going through it, it will store data in a few
> different hashes I have (a one dimensional hash, and two-two dimensional
> hashes).  Once I read in all the data, I then sort the hashes and output all
> of this to a set of log files.
> 
> 
> Here's the main chunk of my code that start the text coming in...
> # Build up the command string appropriately, depending on what options
> # have been set.
> my $command =
>   ($rlog_module ne "") ? "cvs -n -d $cvsdir rlog $rlog_module" : "cvs
> log";
> print "Executing \"$command\"\n" if $debug;
> 
> open (CVSLOG, "$command |") || die "Couldn't execute \"$command\"";
> while ()
> {
> 
> 

what are you doing in here?

> }
> 
> If you can't see what I'm doing, I'm parsing the return of cvs rlog, I'd
> like to run this on the root of our CVS repository and extract statistics
> from that, however, when I run this, I get an "Out Of Memory" error as I'm
> parsing the text.  Is this because I'm using hashes or because there is just
> a lot of text for cvs rlog on the root?  I get the "Out Of Memory" error
> after it runs for like 30 minutes or so and if I watch the process it
> usually gives me that error once it is using about 20 MB of memory.

what is the size of the output text out from the $command?

> 
> I'm new so I don't really know what this could be or where to look for help,
> thanks in advance,
> 
> Jacob
> 


-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...



msg02784/pgp0.pgp
Description: PGP signature


Re: limit the list

2002-11-21 Thread Vladi Belperchinov-Shabanski

oops sorry I've made mistake :( the correct one is:

@arr = qw( this is just a testtestetstett );
$res;
for( @arr )
  {
  $res .= "etc...,", last if length "$res$_" > 10;
  $res .= "$_,";
  }
chop( $res );
print "$res\n";

:)

P! Vladi.


On Thu, 21 Nov 2002 15:01:49 +0200
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> wrote:

> 
> hi,
> 
> my no golf, join, map, RE solution is: :)
> 
> @arr = qw( this is just a test );
> $res;
> for( @arr )
>   {
>   $res .= "$_,";
>   $res .= "etc...,", last if length $res > 10;
>   }
> chop( $res );
> print "$res\n";
> 
> the number 10 is matter of taste, 90 could be nice figure also...
> 
> P! Vladi.
> 
> On Tue, 19 Nov 2002 18:50:36 -0500
> "Selector, Lev Y" <[EMAIL PROTECTED]> wrote:
> 
> > Folks,
> > 
> > Simple question:
> > Is there a more elegant way to express this:
> >   an array of names is converted into a comma-separated list.
> >   if the list gets to long - limit it and add ", etc." at the end.
> > 
> >       $str = join ', ', @names;
> >   if (length($str)>90) {
> > ($str = substr($str,0,90)) =~ s/,[^,]*$/, etc./;
> >   }
> > 
> > Warmest Regards, 
> > Lev Selector, New York
> > 
> 
> 
> -- 
> Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
> Personal home page at http://www.biscom.net/~cade
> DataMax Ltd. http://www.datamax.bg
> Too many hopes and dreams won't see the light...
> 


-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...



msg02765/pgp0.pgp
Description: PGP signature


Re: limit the list

2002-11-21 Thread Vladi Belperchinov-Shabanski
On Wed, 20 Nov 2002 21:01:45 +0100
"A. Pagaltzis" <[EMAIL PROTECTED]> wrote:

> * Jonathan E. Paton <[EMAIL PROTECTED]> [2002-11-20 20:51]:
> > if (@array > $bound) {
> > $array[$bound-1] = ", etc"; # Set element at boundary 
> > $#array = $bound-1; # Shorten array to boundary
> > }
> > 
> > print join ", ", @array;
> 
> Again, that's the same as:
> 
> join ', ', @array[0 .. $bound], @array > $bound ? 'etc' : ();

both are wrong. how can you be sure the resulting string will be
no more than 90 chars (X chars) in length?

for example the first element in the array is 128K :)

> 
> > Now, this I *might* use in production code.  Of course, the
> > obvious mistake is that space between the last element and
> > the ", etc" part - but easily solved by using .= to append
> > to the appropriate element.
> 
> No, it will look like "..blah, , etc" and that's easily
> remedied by using just "etc" since the join adds its own
> ", " anyway.
> 
> -- 
> Regards,
> Aristotle
> 


-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...



msg02764/pgp0.pgp
Description: PGP signature


Re: AW: Function parameter passing (was: Re: limit the list)

2002-11-20 Thread Vladi Belperchinov-Shabanski
On Wed, 20 Nov 2002 13:34:40 -
"Pense, Joachim" <[EMAIL PROTECTED]> wrote:

> Bart Lateur [mailto:[EMAIL PROTECTED]] wrote:
> (Mittwoch, 20. November 2002 11:43)
> 
> >On Wed, 20 Nov 2002 04:10:02 -0600, Steven Lembark wrote:
> >
> >>sub commify
> >>{
> >>my ( $max, $sep, $end ) = ( shift, shift, shift );
> > ...
> >>}
> >
> >Wow! Hold it! Am I the only one who finds this absurd? More than one
> >shift on the same array in one single expressing, sounds like bad style
> >to me. Comments?
> 
> In one of my programs, this would be
> 
> sub commify {
> my $max = shift;
> my $sep = shift;
> my $end = shift;
> 
> ...
> }

I use this form too. it is more explicit and gives nice way to comment:

sub commify {
 my $max = shift; # this is arg 1 blah
 my $sep = shift; # arg two blah
 my $end = shift; # arg III, actually takes hash reference to useless data :)
 
 ...
}

which is better than

  my ( $max,  # ala
   $sep,  # bala
   $end ) # nica
  = @_;

imo.

it is matter of taste of cource...

my ( ... ) = @_;

has the only advantage to be ~20% faster for large number of function call iterations.

finally:

sub nonsensessez
{
  my $s = $_[0];
  my $a = $_[1];
  my $k = $_[2];
  my $j = $_[3];
  my $l = $_[4];

  1;
}

combines the best from both forms above ( i.e. cna be commented, clean and
approx. as fast as `my ( ... ) = @_' thing.

P! Vladi.

> 
> better or even worse in your view?
> 
> Joachim
> 


-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...



msg02736/pgp0.pgp
Description: PGP signature


Re: limit the list

2002-11-20 Thread Vladi Belperchinov-Shabanski

hi,

my no golf, join, map, RE solution is: :)

@arr = qw( this is just a test );
$res;
for( @arr )
  {
  $res .= "$_,";
  $res .= "etc...,", last if length $res > 10;
  }
chop( $res );
print "$res\n";

the number 10 is matter of taste, 90 could be nice figure also...

P! Vladi.

On Tue, 19 Nov 2002 18:50:36 -0500
"Selector, Lev Y" <[EMAIL PROTECTED]> wrote:

> Folks,
> 
> Simple question:
> Is there a more elegant way to express this:
>   an array of names is converted into a comma-separated list.
>   if the list gets to long - limit it and add ", etc." at the end.
> 
>   $str = join ', ', @names;
>   if (length($str)>90) {
> ($str = substr($str,0,90)) =~ s/,[^,]*$/, etc./;
>   }
> 
> Warmest Regards, 
> Lev Selector, New York
> 


-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...



msg02734/pgp0.pgp
Description: PGP signature


Re: [OT] Unicode vs URI escaping

2002-11-19 Thread Vladi Belperchinov-Shabanski
öèòèðàì  Ian Phillipps <[EMAIL PROTECTED]>:

> On Tue, 19 Nov 2002 at 11:30:17 +0200, Vladi Belperchinov-Shabanski
> wrote:
> > 
> > hi!
> > 
> > I hope I understand the problem correctly, i.e. `how to escape'?
> > 
> > In this case I always prefer:
> > 
> > our %ESCMAP = ();
> > for ( 0 .. 255 ) { $ESCMAP{ chr( $_ ) } = sprintf("%%%02X", $_); }
> 
> That's not enough fun:
> 
> our %ESCMAP = map { chr($_) => sprintf "%%%02X",$_ } 0..255;
> 
> :-)

define 'fun' please :)))

> 
> > I did few benchmarks. The results were:
> > (for 1_000_000 iterations over ~20 char string)
> 
> Hmm.. this will depend heavily on the number of escapees in the string.
> If you're expecting hardly any, then the best algorithm may be
> different
> dealing with running text in non-Latin script, where every char will
> match.
> 
> Every now and then, I get this sneaking feeling that I ought to write a
> generalised "pack" that can do this sort of thing. But usually the
> feeling passes.
> 
> Ian
> 

there are no fair benchmark :) anyway I think my benchmark is correct as
long as I set all the functions (being tested) in the same situations
(same input, same iterations count and expecting same correct result)

finally I cannot benchmark the world (i.e. everything) ;)

P! Vladi.
--
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]>
<[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
http://www.biscom.net/~cade  http://cade.webbg.com  



Êàêâî å ðåêëàìà â Èíòåðíåò? - http://reklama.mail.bg



Re: [OT] Unicode vs URI escaping

2002-11-18 Thread Vladi Belperchinov-Shabanski

hi!

I hope I understand the problem correctly, i.e. `how to escape'?

In this case I always prefer:

our %ESCMAP = ();
for ( 0 .. 255 ) { $ESCMAP{ chr( $_ ) } = sprintf("%%%02X", $_); }

sub web_escape
{
  my $text = shift;
  $text =~ s/([^A-Za-z0-9_.-])/$ESCMAP{$1}/g;
  return $text;
}

which I've also seen in one library but I don't remember where
(CGI.pm, LWP?) anyway...

of cource the usual is:

sub usual_escape
{
  my $text = shift;
  $text =~ s/([^A-Za-z0-9_.-])/sprintf("%%%02X", ord($1))/ge;
  return $text;
}

I did few benchmarks. The results were:

(for 1_000_000 iterations over ~20 char string)

web_escape: 18 sec
usual_escape: 22 sec
escape (from the previous message, i.e. below): ~70 sec

P! Vladi.

On Fri, 15 Nov 2002 09:42:08 -0600
[EMAIL PROTECTED] wrote:

> Improvements? Did somebody mention improvements??
> 
> Andy Bach, Sys. Mangler
> Internet: [EMAIL PROTECTED] 
> VOICE: (608) 261-5738  FAX 264-5030
> 
> Programming is a Dark Art, and it will always be. The programmer is 
> fighting against the two most destructive forces in the universe: entropy 
> and human stupidity.  -Damian Conway, Perl Guru
> - Forwarded by Andy Bach/WIWB/07/USCOURTS on 11/15/02 09:40 AM -
> 
> 
> saith: "Niels Poppe" <[EMAIL PROTECTED]>
> Sent by: [EMAIL PROTECTED]
> >
> > I figure a lot of people on this list handle UTF-8 and perl :)
> >
> > What works with URI escaping it?
> >
> > URI::Escape's &uri_escape fails (miscounts bytes/chars somewhere)
> >
> 
> If all else fails, the following does work (on either version of
> perl).
> 
> sub escape {
>   join '', map {
>     chr($_) =~ /([a-zA-Z0-9_.-])/o? $1 : sprintf "%%%02X", $_
>   } unpack 'C*', shift
> }
> 
> Any improvements are welcome.
> 
> Niels
> 
> 


-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...



msg02684/pgp0.pgp
Description: PGP signature


Re: ~9M lines of data

2002-10-25 Thread Vladi Belperchinov-Shabanski
On Mon, 14 Oct 2002 18:44:20 +0200
Abigail <[EMAIL PROTECTED]> wrote:

> On Mon, Oct 14, 2002 at 12:25:03PM -0400, iudicium ferat wrote:
> > I am somewhat beating my head against a brick wall here - so I think "Hey!
> > This sounds like a Fun With Perl project :)"
> > 
> > Here is the challenge -
> > 
> > You are presented with a MySQL Schema dump that is less than 9 million rows;
> > you should read the data row by row, finding each CREATE TABLE statement,
> > and displaying the next ~50 lines INCLUDING this line - do this recursively
> > until end of file is reached.
> 
> 
> grep -A 50 'CREATE TABLE' file.sql
> 

and (my) perl way:

   #!/usr/bin/perl -n
   $c = 50 if /CREATE TABLE/;
   print if $c and $c--;

P! Vladi.
--
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> 
http://www.biscom.net/~cade  http://cade.webbg.com  



msg02621/pgp0.pgp
Description: PGP signature


Re: removing extra empty lines

2002-09-30 Thread Vladi Belperchinov-Shabanski

On Sun, 29 Sep 2002 18:38:04 +0200
Aristoteles Pagaltzis <[EMAIL PROTECTED]> wrote:

> * Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> [2002-09-29 18:25]:
> > #!/usr/bin/perl -p
> > $_='' if !/\S/ && $e;   # i.e. don't print if empty and last one was empty
> > $e = !/\S/; # remember if last one is empty...
> 
> Since you have already done $_='' in the first line, you
> don't need a regex in the second to set $e. You can just say
> 
> $e = !$_;

line `0' will fail this test, though it is not empty line...

P! Vladi.
-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
http://www.biscom.net/~cade  http://cade.webbg.com
Now, sure as the sun will cross the sky, This lie is over
Lost, like the tears that used to tide me over...





Re: removing extra empty lines

2002-09-29 Thread Vladi Belperchinov-Shabanski


hi,

this is mine (a bit more obvious) solution:

#!/usr/bin/perl -p
$_='' if !/\S/ && $e;   # i.e. don't print if empty and last one was empty
$e = !/\S/; # remember if last one is empty...
#eof

:)

P! Vladi.

On Mon, 12 Aug 2002 13:28:19 -0400
"Selector, Lev Y" <[EMAIL PROTECTED]> wrote:

> Folks,
> 
> I have a long file which has many "empty" lines 
> with nothing but may be spaces or tabs (/^\s*$/). 
> 
> These lines tend to group together creating chunks 
> of empty vertical space on the printout. 
> 
> I want to reduce the number of empty lines 
> in such chunks to 1 line.
> 
> What would be an elegant way to do this?
>   
> Warmest Regards, 
> Lev Selector
> 


-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
http://www.biscom.net/~cade  http://cade.webbg.com
Now, sure as the sun will cross the sky, This lie is over
Lost, like the tears that used to tide me over...





testing, was: Re: Possible improvements...

2001-12-12 Thread Vladi Belperchinov-Shabanski

Eugene van der Pijll wrote:
> > 8. Fairness
> >
> > I think the key to a fair game is a really tight test program
> > on day one (tsanta.pl had too many holes). It is ideal if you
> > can just say "if it passes the test program, it is ok";
> > that also eliminates ambiguity about the game's semantics
> > and spares you from having to describe the semantics.
> 
> I don't think that can be done. Some rules should have been a bit
> clearer, but you can't foresee every loophole that will be used.
> 
> I found the test program very useful, so as a referee I will make it
> public at the start of the competition. However, programs that pass the
> test program but have fatal effects (output to STDERR, fail for n>100
> etc.) will be disqualified.
> 
> Eugene

  besides that solutions are great, funny, clever, beautifull, they are
  mostly useless in real work! I'm soure that noone optimizes his(her?)
  tail.pl for few days to do the work which is supposed to do, isn't it?

  so I think that the rule should be only `if test program says ok, then
  it is ok'... possibly holes could be announced during the contest but
  the test program should stay the same 'till the end. If someone finds
  a way to use hole, so let it be -- it is just fun, noone depends
  tragically on all this I'm sure.

  the point is that if the program dies after output correct information
  it is ok, but if it prints with die (for example) it won't be catched
  by the test program so it is fail. if the program possibly can output 
  the first 10 lines but cannot do for the first 100, so the test should
  be aware of this... (well something like this)

P! Vladi.
-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...


smime.p7s
Description: S/MIME Cryptographic Signature


Re: Possible improvements for the next golf apocalypse

2001-12-10 Thread Vladi Belperchinov-Shabanski

Piers Cawley wrote:
> >
> > I think a weekend would be fine (i.e. 2 non-working days)
> 
> I don't. I don't tend to do much coding on the weekend, but I do quite
> a bit in the evening and on the train during the week. And I think

This is very personal, I don't have much free time during the (working)
week and even I prefer not to code in the evening after a nasty long
working days... you got that, don't you?

Well perhaps most people don't have work to do, I don't know... :/

> that drawing a distinction between newbies and gurus is somewhat
> invidious too, but I can't begin to articulate why.
> 

?)

> 
> >> > 2. Tie-breaking rule
> >> >
> >> > I chose to break ties by rewarding the first to post.
> >> > I suppose other ways are possible (e.g. reward the more
> >> > efficient one) but they all seem a little artificial.
> >>
> >> This seems fair to me.  First in Best dressed.  I don't think that
> >> efficiency and Golf should ever be mentioned in the same sentence :)
> >
> > `First wins' is not good IMO, perhaps some additional scoring like
> > for example using non-average(usual) solution is better? this is
> > arguable of cource but it is just an idea... of cource this won't
> > be factor for different strokes count solutions...
> 
> The beauty of 'first in breaks the tie' is that it's objective. Which

Depends very much of the free time you can use! It is *NOT* objective unless
you get all players in a room and you give them timelimit!

> is a good thing. And even if you did come up with a subjective measure
> based on 'non standardness' or 'elegance' or whatever, the results
> show that once you get down to minimal length, often the only
> difference between two solutions is the choice of variable names or
> where they put the brackets in a regex, so you'd need another tie
> breaker anyway.
> 
> It might be nice to see a "Judge's Prize" for the solution that the
> judge liked best. It doesn't even have to be the shortest. (It doesn't
> even have to qualify, given how much "-p 11..&" tickled the judge this
> time 'round)

voting between players? long-term leaderboard? finally this is not easy
problem...

> 
> >> > 3. Number of Holes
> >> >
> >> > Though 9/18 is traditional in golf, five seemed sufficient to
> >> > provide an interesting spread of scores. Any more than five
> >> > may be unnecessarily cruel.
> >>
> >> No more than 6.
> >
> > 8 :)
> 
> Well, it is a round number, I'll give you that. But I think I prefer six.

4.

> 
> >> > 4. Hole Difficulty
> >> >
> >> > When I posted the game, I thought the holes were too easy. In
> >> > retrospect, I think they were about right because they were
> >> > simple enough to allow novice golfers to have a go, while still
> >> > providing a challenge for the elite golfer.
> >>
> >> This level was good. As a newbie, I was certain that I could
> >> complete the game thought I wouldn't be too far off the pace.
> >
> > nothing is too easy :) I think any task wich can be solved with
> > regular, readable, non-tricky, few lines (screenpage?) solution will
> > be ok
> 
> Easy is definitely good. It might be nice to see one hole be a 'Take
> this program and make it shorter' type challenge though. And that
> could be something with reasonably complex behaviour...

YES! I like it... :)

P! Vladi.
-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...


smime.p7s
Description: S/MIME Cryptographic Signature


Re: Possible improvements for the next golf apocalypse

2001-12-10 Thread Vladi Belperchinov-Shabanski

"Anthony J. Breeds-Taurima" wrote:
> 
> On Sun, 9 Dec 2001 [EMAIL PROTECTED] wrote:
> 
> > While it is still fresh in everyone's minds, I thought I should
> > make some notes on possible improvements for the next apocalypse.
> >
> > 1. Timing
> >
> > We probably all spent more time on this than we can afford.
> > I think 5 days was too long; 2-3 days feels about right.
> >
> > It seems fairest to announce the game start time two weeks (say)
> > before the event, to give people time to prepare.
> 
> I think that 5 days was good. Or you could have 2 games going
> Newbies and Guru.  The Holes would be the same BUT the duration would be
> different. ie (Newbies 5 days, Guru 2-3 days).  Update the scores and announce
> the winners at the 2-3 day mark BUT don't release the code.  Would that be too
> cruel a punishment for the gurus.

I think a weekend would be fine (i.e. 2 non-working days)

> 
> > 2. Tie-breaking rule
> >
> > I chose to break ties by rewarding the first to post.
> > I suppose other ways are possible (e.g. reward the more
> > efficient one) but they all seem a little artificial.
> 
> This seems fair to me.  First in Best dressed.  I don't think that
> efficiency and Golf should ever be mentioned in the same sentence :)

`First wins' is not good IMO, perhaps some additional scoring like
for example using non-average(usual) solution is better? this is
arguable of cource but it is just an idea... of cource this won't
be factor for different strokes count solutions...

> 
> > 3. Number of Holes
> >
> > Though 9/18 is traditional in golf, five seemed sufficient to
> > provide an interesting spread of scores. Any more than five
> > may be unnecessarily cruel.
> 
> No more than 6.

8 :)

> 
> > 4. Hole Difficulty
> >
> > When I posted the game, I thought the holes were too easy.
> > In retrospect, I think they were about right because they were
> > simple enough to allow novice golfers to have a go, while still
> > providing a challenge for the elite golfer.
> 
> This level was good.  As a newbie, I was certain that I could complete the
> game thought I wouldn't be too far off the pace.

nothing is too easy :) I think any task wich can be solved with regular,
readable, non-tricky, few lines (screenpage?) solution will be ok

> 
> > 5. Individual Hole Scores - to post or not to post?
> 

don't -- just total.

P! Vladi.
-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...


smime.p7s
Description: S/MIME Cryptographic Signature


Re: Santa Hole 5 (wc.pl) Post Mortem

2001-12-07 Thread Vladi Belperchinov-Shabanski

BooK wrote:
> 
> En réponse à Piers Cawley <[EMAIL PROTECTED]>:
> 
> > Ian Phillipps <[EMAIL PROTECTED]> writes:
> > >> --- Tim Ayers  21
> > >> #!/usr/bin/perl
> > >> printf"%010d\n",$.,<>
> > >
> > > Harumph. I remember something like this approach flitting through my
> > > mind, but, I thought, the $. would be evaluated before the <>, so it
> > > would be zero.
> > >
> > > Moral: try it!

first I thought `but of cource', a bit later I was a bit confused... :)

more clear would be something like:

<>;printf"%010d\n",$.

which does not work?! as I see it this is void context, but seems like I'm wrong
'cos it takes away one line... well list context can be forced:

@_=<>;printf"%010d\n",$.

I don't know why I did something like

printf"%010d\n",$_=@_=<>

which is the same :)

> > >
> > > Hmm... why isn't it zero?
> >
> > Because perl passes arguments by reference. So $. gets shoved on the
> > stack (as $.) and <> gets evaluated in an array context so that the
> > results can be shoved on the stack. So, when printf comes to read the
> > value of $. '<>' has already been evaluated.
> 
> So I guess
> 
> #!/usr/bin/perl
> printf"%010d\n","$.",<>

P! Vladi.
-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...


smime.p7s
Description: S/MIME Cryptographic Signature


Re: The Santa Claus Golf Apocalypse

2001-12-06 Thread Vladi Belperchinov-Shabanski


20*100 (how big is the leaderboard?) is 2k so it *wouldn't be a very long email 
message* really

:)

the point is to see all the solutions and how are they combined...
well second is very vague perhaps :))

P! Vladi.

Bernie Cosell wrote:
> 
> On 5 Dec 2001, at 13:14, Vladi Belperchinov-Shabanski wrote:
> 
> > IMO it is better to post everyone's solutions (regardless duplications)
> > it won't be big message (still there were longer ones I guess)...
> 
> Indeed.  At about 100chars per entry, it wouldn't be a very long email message,
> would it... :o).
> 
> On the other hand, if they were annotated with some hints for the less-twisted-
> of-mind as to how/why they worked, then judging from how bizarre some of the
> approaches seem to be [gleaned from the second-hand discussions here], I
> suspect that THAT would be a _much_ longer email mesasge...
> 
>   /Bernie\
> 
> --
> Bernie Cosell Fantasy Farm Fibers
> mailto:[EMAIL PROTECTED] Pearisburg, VA
> -->  Too many people, too few sheep  <--

-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...


smime.p7s
Description: S/MIME Cryptographic Signature


Re: I vote...

2001-12-05 Thread Vladi Belperchinov-Shabanski


ok I give up -- never used this and probably will never do...

thanx for the hint!

P! Vladi.

Robin Houston wrote:
> 
> On Wed, Dec 05, 2001 at 02:17:40PM +0200, Vladi Belperchinov-Shabanski wrote:
> >   so it looks like it is undocumented really, isn't it?
> 
> >From L:
> 
>If either operand of scalar ".." is a
>constant expression, that operand is implicitly compared
>to the $. variable, the current line number.
> 
>  .robin.

-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...


smime.p7s
Description: S/MIME Cryptographic Signature


Re: I vote...

2001-12-05 Thread Vladi Belperchinov-Shabanski

Jérôme Quelin wrote:
> 
> > ps: can anyone explain how (well, why!) the -p11..& tail works? :)
> 
> Despite of my poor golf-score (107), I understood this one...
> 
> perl -pe'11..&' is the same as:
> while(<>){
>  11..&;
> } continue {
>  print;
> }

  yep this is obvious

> 
> The .. must be understood as the flip-flop operator: eval first part until it
> gets true, then eval second part until it gets true.

  I've read flip-flop operator description in the camel book but...

> When evaluating a test that is a single number, perl compares with line
> number (ie, $.).

  which is strange! accordingly to this, the code (for example):

  while(<>){ print if 10; }

  should print 10th line only ($. == 10) which is not correct...

> So the script tests if $. is equal at 11, when this becomes true (it has
> already printed the 10 first lines), perl tries to evaluate the second part.
> But second part is a call to the 'Main::' subroutine, which does not exist:
> perl crashes.
> 

  so it looks like it is undocumented really, isn't it?

P! Vladi.
-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...


smime.p7s
Description: S/MIME Cryptographic Signature


Re: The Santa Claus Golf Apocalypse

2001-12-05 Thread Vladi Belperchinov-Shabanski


IMO it is better to post everyone's solutions (regardless duplications)
it won't be big message (still there were longer ones I guess)...

well at least I'm curious :)

P! Vladi.

Eugene van der Pijll wrote:
> 
> [EMAIL PROTECTED] schreef op 05 december 2001:
> > Given that tsanta.pl has many loopholes, a panel of experts will
> > than examine the leading solutions for correctness (disqualifying
> > an entry that fails for files longer than 100 lines, for example).
> > To avoid an obvious conflict of interest, I suggest that only
> > non-competitors be invited to the panel.
> 
> Just post the entries of the top-5 to fwp, and let everyone comment,
> including the competitors.
> 
> > Please let me know when you think we should end the game.
> 
> As soon as possible.
> 
> Eugene

-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...


smime.p7s
Description: S/MIME Cryptographic Signature


I vote...

2001-12-05 Thread Vladi Belperchinov-Shabanski


to end this madness! :)

the leaderboard is full (more or less) and is perhaps scoreas are average and true...
well still anyone can post better solution(s) later :)

anyway it was fun and I'd like to thank you all!
good luck to the finalists!

P! Vladi.
ps: can anyone explain how (well, why!) the -p11..& tail works? :)
-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...


smime.p7s
Description: S/MIME Cryptographic Signature


Re: The Santa Claus Golf Apocalypse

2001-12-05 Thread Vladi Belperchinov-Shabanski

Jeff 'japhy' Pinyan wrote:
> 
> Geez, I have three different solutions for tail.pl, ALL the same length
> (19 chars).  Has someone gotten below 19?
> 

  I stuck on 19 too and I don't think it can be shorter :)
  (this could sound like trying to put out a fire with gasoline
  but I really think so...)

  btw: I'm more interested if there is fancy rev.pl version instead
  of the obvious (usual) one? I fixed several times each one of the
  holes except this one...

  anyway, I'm at 97 w/o undocumented tricks :) and I think to stop here...

P! Vladi.
-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...


smime.p7s
Description: S/MIME Cryptographic Signature


Re: middle line (was Re: Daily Perl FAQ...)

2001-11-30 Thread Vladi Belperchinov-Shabanski

hi!

  `recursion' means `memory' (i.e. stack) I'm sure there is
  few line-recursive function that could do the trick but
  this is not the point, the point is that you cannot do this without 
  memory and then you better use arrays :)

P! Vladi.

Greg Bacon wrote:
> 
> In message <3C074313.2038.6FC2633@localhost>,
> "Keith C. Ivey" writes:
> 
> : Greg Bacon <[EMAIL PROTECTED]> wrote:
> :
> : > You have a finite sequence of unknown length, where each
> : > element in the sequence is a string.  Output the middle
> : > element of the sequence (for a reasonable definition of
> : > middle), traversing the sequence at most once and without
> : > storing the elements in an array.
> :
> : Okay, you've clarified what the input is like.  Now we need
> : clarification of what "without storing the elements in an
> : array" means.
> :
> : Does "the elements" mean "all the elements" or "any elements"?
> : Does "an array" mean you can store whatever elements you want,
> : as long as you don't use a Perl array to do it?
> 
> I give up. :-)
> 
> Here's my solution (which is similar but less elegant than the one
> Ian sent):
> 
> #! /usr/local/bin/perl
> 
> use warnings;
> use strict;
> 
> sub usage { "Usage: $0 file\n" }
> 
> sub midline {
> my $fh   = shift;
> my $lnum = shift || 1;
> my $sub  = shift || sub { undef };
> 
> my $line = <$fh>;
> 
> if (defined $line) {
> my $next = sub {
> my $n = shift;
> 
> if ($n == $lnum) {
> return $line;
> }
> else {
> return $sub->($n);
> }
> };
> 
> midline($fh, $lnum+1, $next);
> }
> else {
> $sub->(int $lnum/2);
>     }
> }
> 
> die usage unless @ARGV == 1;
> my $file = shift;
> my $fh;
> 
> open $fh, $file or die "$0: open $file: $!\n";
> 
> my $mid = midline($fh) || "\n";
> print $mid;
> 
> To answer Vladi: yes, magic is needed, i.e., recursion.
> 
> Greg

-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...


smime.p7s
Description: S/MIME Cryptographic Signature


Re: middle line (was Re: Daily Perl FAQ...)

2001-11-30 Thread Vladi Belperchinov-Shabanski

hi!

  actually are those snippets are exactly equal to:

  @a = <>;
  print $a[@a/2];

  using big string is the same as using array, so if the
  `perl -p0 -e...'s are solutions then the rule `not using
  arrays' seems quite artificial and senseless...

P! Vladi.
ps: the example above has one big advantage over `perl -p0 -e's and it is
that is far more readable and stable :)))

Yanick wrote:
> 
> On Thu, Nov 29, 2001 at 08:51:36PM -0500, Yanick wrote:
> > On Thu, Nov 29, 2001 at 08:49:10PM -0500, Yanick wrote:
> > > On Thu, Nov 29, 2001 at 08:01:27PM -0500, Jeff 'japhy' Pinyan wrote:
> > > > On Nov 29, Yanick said:
> > > >
> > > > >> > perl -p0 -e'1while s/.*?\n(.*\n).+\n?/$1/s;s/\n.*//'
> > > > >>   perl -p0 -e'1while s/.*?\n(.*\n).+\n?/$1/s;s/\n.*//'  (Yanick)
> > > > >>   perl -p0 -e'$n=y|\n||>>1;s/(.*\n){$n}//;s/\n.*//s'(Andrew)
> > > > >>   perl -p0 -e'$n=1+y|\n||/2;/(.*\n){$n}/;$_=$+' (Yv2.0)
> > > >
> > > >  perl -p0 -e'$n=1+y|\n||/2;($_)=/(.*\n){$n}/'  (japhy)
> > >
> > >perl -p0 -e'1while($_)=/\n(.*)\n/s;$_=$1'     (Yv3.0)
> >perl -p0 -e'$_=$1 while/\n(.*)\n/s'   (Yv3.1)
>  perl -p0 -e'$_=$1while/\n(.*)\n/s'   (Yv3.2)
> 
> And that's the end for tonight, I swear...
> 
> Joy,
> Yanick

-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...


smime.p7s
Description: S/MIME Cryptographic Signature


Re: middle line (was Re: Daily Perl FAQ...)

2001-11-30 Thread Vladi Belperchinov-Shabanski

Greg Bacon wrote:
> 
> In message <[EMAIL PROTECTED]>,
> Greg Bacon writes:
> 
> : Yesterday, I saw an interesting related exercise.  Write a program that
> : reads the lines from a file and outputs the middle line.  The kicker is
> : that you can't use arrays.  (Note that there's a little ambiguity with
> : respect to the definition of "middle line" when the number of lines in
> : the file is even or when there is only one line.  Just pick a reasonable
> : definition and get to work.)
> 
> Sorry, I wasn't clear on an important point.  You only get one pass
> through the file.
> 
> Greg

  then there is no solution! in any case you have to count number of newlines
  so you have to either save data to memory or scan file and get back to the middle...

  going back to the middle point is actually `second pass' and does not count!

  doing some cheap tricks with tell/seek requires to save newlines locations which
  as I said is `second pass' really (even don't mention that you need memory to save
  those locations)

  finally if you add and something like: `it should work on a stream, i.e. filter' then
  we need a magic for this :)))

  even it the latest case there is simple memory solution if you tell if using arrays 
is
  equal to using memory (even external like second file which will pass the rules but 
will
  take extra disk space;))...

P! Vladi.
-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...


smime.p7s
Description: S/MIME Cryptographic Signature


Re: Feel good benchmarks

2001-11-20 Thread Vladi Belperchinov-Shabanski

hi,

  the C demo at the end is out of topic, isn't it?

  it was really interesting for me how performance changed
  between perl versions and other languages (interpreters/
  scripts/etc.) but C points just nothing (actually result
  is quite obvious:))...

P! Vladi.

Michael G Schwern wrote:
> 
> Some of you may get depressed thinking about all this bloat we've put
> into the language to drag it down.
> 
> Well, I've developed a truely rigorous benchmark designed to show how
> far Perl has come:
> 
> sub f {
> my($num) = shift;
> return $num if $num <= 1;
> return f($num-1) + f($num-2);
> }
> 
> print f(25);
> 
> bleadperl
> real0m2.282s
> user0m2.210s
> sys 0m0.010s
> 
> Debian's 5.6.1
> real0m2.643s
> user0m2.510s
> sys 0m0.020s
> 
> My own compiled 5.6.1
> real0m2.141s
> user0m2.080s
> sys 0m0.020s
> 
> 5.005_03
> real0m2.180s
> user0m2.140s
> sys 0m0.010s
> 
> 5.004_05
> real0m2.342s
> user0m2.140s
> sys 0m0.160s
> 
> 5.004_04
> real0m5.515s
> user0m5.380s
> sys 0m0.110s
> 
> 5.004
> real0m5.542s
> user0m5.340s
> sys 0m0.150s
> 
> 5.003_07
> real0m5.581s
> user0m5.340s
> sys 0m0.200s
> 
> So we're doing something right.  And this lame benchmark might
> actually be useful in convincing some luddite 5.004_04 user to upgrade
> Perl.
> 
> And for comparative purposes
> 
> def f(num)
> return num if num <= 1
> return f(num-1) + f(num-2)
> end
> 
> print f(25)
> 
> Ruby 1.6.5
> real0m2.225s
> user0m2.190s
> sys 0m0.000s
> 
> Oh dear.  And it took one less line, too.
> 
> And just to end this feel good email on a real downer:
> 
> #include 
> 
> int f (int num) {
> if( num <= 1 )
> return num;
> return f(num-1) + f(num-2);
> }
> 
> int main (void) {
> printf("%d", f(25));
> }
> 
> gcc 2.95.4
> real0m0.077s
> user0m0.030s
> sys 0m0.000s
> 
> --
> 
> Michael G. Schwern   <[EMAIL PROTECTED]>http://www.pobox.com/~schwern/
> Perl Quality Assurance  <[EMAIL PROTECTED]>     Kwalitee Is Job One
> OH GOD!!  It's LINUX!  All you Linux fanboys go wild!  It never crashes!
> It'll wash your underpants!  It'll eat your dog for you, if you want your
> dog to be eaten!  It'll make you attractive and smell good and... it'll...
> uh... uh.  Man, I'm so sick of this shit.
> http://www.goats.com/archive/000602.html

-- 
Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
Personal home page at http://www.biscom.net/~cade
DataMax Ltd. http://www.datamax.bg
Too many hopes and dreams won't see the light...


smime.p7s
Description: S/MIME Cryptographic Signature