perl.fwp
  Home FAQ Contact Sign in
perl.fwp only
 
Advanced search
April 2008
motuwethfrsasuw
 123456 14
78910111213 15
14151617181920 16
21222324252627 17
282930     18
2008
 Jan   Feb   Mar   Apr 
 May   Jun   Jul   Aug 
 Sep   Oct   Nov   Dec 
2008 2007 2006  
total
perl.fwp Profile…
RELATED GROUPS

POPULAR GROUPS

more...

 Up
  YN golf         


Author: Uri Guttman
Date: Mar 31, 2008 15:50

someone posted (and it wasn't homework) for an easy way to get all
possible combos of YN (5 chars so 32 answers). he got some basic
multiline answers but i think it makes for a great golf problem.

here is my first pass which i am sure can be easily bested. i haven't
even squeezed out the white spaces but it does work.

golf away!

uri

perl -le 'print join "\n", map {tr/01/NY/; $_} map unpack( "b5", chr), 0 .. 31'

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
9 Comments
  Name the secret operator         


Author: Philippe Bruhat
Date: Mar 19, 2008 17:28

Hi,

while doing some research for a talk on Perl secret operators, I tried
to find who first coined the term "secret operator".

I found a post from Greg Allen on February 2004 on this very list
(http://groups.google.com/group/perl.fwp/msg/e62668a760de1652),
and then a post by Abigail on comp.lang.perl.misc on January 2003
(http://groups.google.com/group/comp.lang.perl.misc/msg/22cfcd81a1521ec4).

Does anyone know of an earlier occurence of the term?

Now that I have seen Abigail's post on clpm, I want to know its name.
It is the longest secret operator I've seen, and also the only one
that must be on three lines (not counting the content).

<>
(commented out code and pod goes here)
m
;

I have a few ideas for names, but they don't fit very well, and do not
describe the "m\n;" part of the operator.

--
Philippe Bruhat (BooK)
Show full article (1.01Kb)
1 Comment
  RE: regex of the month (decade?)         


Author: Steven R. Stoll
Date: Jan 8, 2008 08:25

You're right. Mistook it for (.\s) for some reason. My description of .*
still stands however.

But the following should be:
(p(ost)?[.\s]*o(ffice)?[.\s]*box)

post(anynumberofperiodsorspacecharacterclassitems)office(anynumberofperiodso
rspacecharacterclassitems)box

p(anynumberofperiodsorspacecharacterclassitems)o(anynumberofperiodsorspacech
aracterclassitems)box

p(anynumberofperiodsorspacecharacterclassitems)office(anynumberofperiodsorsp
acecharacterclassitems)box

post(anynumberofperiodsorspacecharacterclassitems)o(anynumberofperiodsorspac
echaracterclassitems)box

Steve

-----Original Message-----
From: Keith Ivey [mailto:keith@iveys.org]
Sent: Tuesday, January 08, 2008 10:27 AM
To: Fun with Perl
Subject: Re: regex of the month (decade?)
Show full article (1.35Kb)
no comments
  RE: regex of the month (decade?)         


Author: Steven R. Stoll
Date: Jan 8, 2008 06:59

After solving the case sensitivity issue, separating the alternations, and
solving the un-escaped /, here is what we are left with.

(p(ost)?[.\s]*o(ffice)?[.\s]*box)
po(b|x|drawer|stoffice|[ ]bx|box)
p[\/]o
b(x|ox|uzon)
a(partado|ptdo)

Which matches:
(p(ost)?.*o(ffice)?.*box)

post(anynumberofanythingexceptnewline)office(anynumberofanythingexceptnewlin
e)box
p(anynumberofanythingexceptnewline)office(anynumberofanythingexceptnewline)b
ox
post(anynumberofanythingexceptnewline)o(anynumberofanythingexceptnewline)box
p(anynumberofanythingexceptnewline)o(anynumberofanythingexceptnewline)box

po(b|x|drawer|stoffice|[ ]bx|box)
Show full article (1.74Kb)
2 Comments
  regex of the month (decade?)         


Author: Uri Guttman
Date: Jan 7, 2008 14:06

^([Pp]([Oo][Ss][Tt])?[.\s]*[Oo]([Ff][Ff][Ii][Cc][Ee])?[.\s]*[Bb][Oo]
[Xx])|[Pp][Oo]([Bb]|[Xx]|[Dd][Rr][Aa][Ww][Ee][Rr]|[Ss][Tt][Oo][Ff][Ff]
[Ii][Cc][Ee]|[ ][Bb][Xx]|[Bb][Oo][Xx])|[Pp][/][Oo]|[Bb]([Xx]|[Oo][Xx]|
[Uu][Zz][Oo][Nn])|[Aa]([Pp][Aa][Rr][Tt][Aa][Dd][Oo]|[Pp][Tt][Dd][Oo])

the challenge: itemize the stupidities. the case issue is only 1! i
don't want to even post the 'spec' unless asked for it. i saw this on
usenet today.

enjoy!!

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
11 Comments
  Re: bad code to good golf         


Author: A. Pagaltzis
Date: Dec 9, 2007 13:00

* Uri Guttman stemsystems.com> [2007-12-09 19:25]:
> * Michael G Schwern pobox.com> writes:
>> sub new {
>> my $class = shift;
>> return bless( {@_}, $class );
>> }
>
> my clean version is:
>
> sub new {
> my ( $class, %%self ) = @_ ;
> return bless \%%self, $class ;
> }
>
> i don't like using shift for args if i can help it.

Personally I *always* use `shift` for the invocant, but
assignment from `@_` for all other parameters in all but a few
rare circumstances. So methods in my code always read something
like this:
Show full article (1.16Kb)
no comments
  Re: bad code to good golf         


Author: Marcus Holland-Moritz
Date: Dec 9, 2007 12:15

On 2007-12-09, at 13:23:11 -0500, Uri Guttman wrote:
>>>>>> "MGS" == Michael G Schwern pobox.com> writes:
>
>> sub new {$a=shift;bless{@_},$a}
>
>> 21. And it's even strict clean. :)
>
> that is nice. the other replies beat it though!

Nope, Michael's solution is just as short. We're all stuck
at 21. :-)

--
inbox, n.:
A catch basin for everything you don't want to deal with, but
are afraid to throw away.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Show full article (0.64Kb)
4 Comments
  Fun with Boggle         


Author: Brad Greenlee
Date: Dec 6, 2007 09:44

I haven't written any Perl for fun in a while, but I recently
entertained myself a bit by writing a Boggle puzzle solver in Ruby:

http://blog.footle.org/2007/12/05/cheating-for-fun/

I'm not sure if this particular puzzle has come up before in FWP, but
I was curious as to how closely this yak could be shaved in Perl. I
suspect Ton could do it in somewhere around 40 characters. Anyone
interested?

Brad
1 Comment
  new "!"-based secret operators         


Author: Dmitry Karasik
Date: Nov 30, 2007 00:27

Good news everyone!

Excuse exclamation marks abound, but this message is all about a set of new
secret operators I thought of, all based on the exclamation sign. The boolean
negation is not really often used, but when is, the brevity of "!" cannot be
overestimated.

Anyway, here's a set of conditional decrement/increment operators:

$x +=!! $y is same as $x++ if $y;
$x -=!! $y -- $x-- if $y;
$x +=! $y -- $x++ unless $y;
$x -=! $y -- $x-- unless $y;

and for the completeness sake,

$x *=!! $y -- $x = 0 unless $y ,
$x *=! $y -- $x = 0 if $y;

This bunch, I think, can be appropriately named "screwdriver operators":

-=! and -=!! - flathead
+=! and +=!! - phillips
*=! and *=!! - torx

I don't know what name fits best to distinguish between ! and !! versions
though.
Show full article (2.58Kb)
2 Comments
  hashes over easy         


Author: Uri Guttman
Date: Nov 28, 2007 21:28

hi all,

thanks for the help with hash ideas. the class went pretty well today
with even the most experienced perl coder learning something new about
hash slices. i did some editing of more examples or variations that
aren't on the slides and those helped a bit. the slides are at:

http://sysarch.com/computershare/hashes/index.html

yes, i know the sets slide is empty. i didn't have time to write it.

you can show these slides to others but attribute them to me, please. i
didn't even put copyright notices in the templates so don't rip me off
for my lifetime + 75 years!

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
2 Comments
 
1 2 3 4 5