Re: unhead

2004-09-25 Thread Keith C. Ivey
Randal L. Schwartz [EMAIL PROTECTED] wrote:

 perl -ne 'print unless 1..5'

  perl -pe '$_ x=!(1..5)'

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: unhead

2004-09-25 Thread Keith C. Ivey
Randal L. Schwartz [EMAIL PROTECTED] wrote:

 Keith   perl -pe '$_ x=!(1..5)'
 
 FWP.  Not Golf. :)

Well, I'm sure there's something better than that for golf (Ton 
probably has a 3-byte solution), but I think x= with a boolean 
righthand side *is* fun, and it's even handy for one-liners 
occasionally once you've gotten used to it.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: Load-Bearing Warnings

2004-08-08 Thread Keith C. Ivey
Bart Lateur [EMAIL PROTECTED] wrote:

 Not fun but...
 
 Use
 
  local $^W;
 
 near where the bulk of the warnings are coming from, assuming
 it's safe to be ignored, maybe just these lines in their own
 block.

Or just initialize the variables and avoid the warnings.
Still not fun, though.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: Is this fun?

2003-07-15 Thread Keith C. Ivey
A. Pagaltzis [EMAIL PROTECTED] wrote:

 More than those you mention - because it doesn't parse HTML,
 just looks for some string bits. It will blow up on
 
 img alt=a r g h ...

True, but in the real world (or at least that part of it I 
experience), you're more likely to run into something like

   img src=http://www.example.com/images/abcd.gif

which will be handled by the regex but may cause a parser to 
blow up (though some are more tolerant than others).  It's sad 
that such code exists, it's sad that browsers tolerate it 
without complaint, but we have to deal with it.

Unfortunately, stuff on pages encountered in the wild often 
isn't valid HTML -- in fact that was the whole point of the 
exercise here.  Valid HTML would have had the closing tags 
already.  And the stuff being produced isn't valid HTML 
either, since the tags may be misnested.

Sometimes parsing is overkill.  If regexes are good enough for 
Tim Bray, they're good enough for me:

|   That leaves input data munging, which I do a lot of, and a
|   lot of input data these days is XML. Now here's the dirty
|   secret; most of it is machine-generated XML, and in most
|   cases, I use the perl regexp engine to read and process
|   it. I've even gone to the length of writing a prefilter to
|   glue together tags that got split across multiple lines,
|   just so I could do the regexp trick.

http://www.tbray.org/ongoing/When/200x/2003/03/16/XML-Prog

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: Is this fun?

2003-07-14 Thread Keith C. Ivey
Jon Bjornstad [EMAIL PROTECTED] wrote:

 I had a fragment of HTML that I needed to search
 for imbalanced tags and then remedy the
 situation by appending the right number of closing tags.
 
 my ($no, $nc);
 for my $t (qw(ol ul b i u a)) {
  $no = $frag =~ s/$t\b/$t/gi;
  $nc = $frag =~ s#/$t\b#/$t#gi;
  $frag .= /$t x ($no-$nc) if $no  $nc;
 }
 
 How about that last line? :)
 I don't often get to use the '.' operator or the 'x' operator
 and I thought this was pretty cool.

You don't often use the . operator?  No step-by-step 
construction of strings?  You *are* missing out on fun -- or 
maybe now.

Anyway, here's a very similar bit from a program I wrote some 
months back:

# Close unclosed tags:
for my $tag ( 'FONT', 'B' ) {
my $uc_desc = uc($description);
my($opens, $closes) = (0, 0);
$opens++ while $uc_desc =~ m{$tag}g;
$closes++ while $uc_desc =~ m{/$tag}g;
$description .= /$tag x ( $opens - $closes )
if $opens  $closes;
}

I can't remember why I made an uppercase copy rather than 
using the /i modifier.  I'm sure I had some reason.  As to why 
I made the copy inside the loop, that seems to have been just 
an oversight.  I didn't use \b in the matches, but FONT and B 
were really the only HTML tags that occurred in the fragments 
I was dealing with.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: Converting a textfile-like string to an array and back

2003-02-10 Thread Keith C. Ivey
Yitzchak Scott-Thoennes [EMAIL PROTECTED] wrote:

 Only if you say $x eq  means no lines instead of one empty
 line missing its \n :)

Well, the subject line does say textfile-like, and a 0-byte 
text file has no lines, not one empty line.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: Perl Challenges, Anywhere?

2002-09-09 Thread Keith C. Ivey

WC -Sx- Jones [EMAIL PROTECTED] wrote:

 Given:  fcjjf1CkQsV1IFCCJ25145245
 
 Can you devise a way to break the code? 

Clearly the encryption is a simple xor with
\x2c\x16\x19\x1e\x46\x50\x2d\x04\x25\x1b\x33\x43 . 
\x69\x16\x26\x31\x26\x12\x5d\x50\x57\x5e\x57\x46\x19.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: Thirty Two Camels

2002-05-15 Thread Keith C. Ivey

[EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 You can further combine the above options, each combination
 producing a different camel, for example:
 
 perl camel.pl uri

which produces a large, bearded camel with a ponytail, glasses, 
and a tie-dyed T-shirt.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: Teams?

2002-04-05 Thread Keith C. Ivey

Stephen Turner [EMAIL PROTECTED] wrote:

 No, sorry, I misdirected my reply because of (i) lack of
 Reply-To on the golf mailing list and (ii) temporary brain
 error.

Argh!  I was wondering why there was so little golf discussion 
on either golf list.  I seem to have been dropped from 
[EMAIL PROTECTED] a week or so ago.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: regex for html img... tags

2002-03-18 Thread Keith C. Ivey

Greg Bacon [EMAIL PROTECTED] wrote:

 I coined the phrase Perl golf, but the flood of golf threads have
 made golf really, really boring.

And what better name for something really, really boring than 
golf (apologies to fans of non-Perl golf)?  
 
 IMHO, the volume of golf traffic on fwp warrants the creation of
 [EMAIL PROTECTED]

Sounds reasonable, although I'd hope it wouldn't cause too much 
withering of FWP.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: TPR1 post-mortem

2002-03-08 Thread Keith C. Ivey

Marcelo E. Magallon [EMAIL PROTECTED] wrote:

  A question of my own: why doesn't
 
 s/\B.\B/$$/g
 
  work as I expect, namely abcd - abbccd.  I really can't figure it
  out by reading the docs.

I wondered that too.  I figured it was because \B wouldn't match 
twice at the same place, but then I saw that s/\B./$$/g didn't work 
as expected either.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: TPR(0,1) scores

2002-03-04 Thread Keith C. Ivey

Stephen Turner [EMAIL PROTECTED] wrote:

 Funny, I thought I'd had several epiphanies, and yet I'm still a
 stroke behind you...

I apologize for my unseemly whining.  I've been punished for it 
by being dropped from 7th to 11th place overnight.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: TPR(0,1) scores

2002-03-03 Thread Keith C. Ivey

[EMAIL PROTECTED] wrote:

 Unfortunately, I have been reduced to hanging on to Keith and
 Stephen like a leech. :-(

Looks like the leech has detached itself.  You've shot up to 
second place, 5 strokes ahead of me.  I don't seem to be 
getting the epiphany yet, so I guess I've got a few days of 
obsession to go.


-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: TPR(0,1) scores

2002-03-02 Thread Keith C. Ivey

Stephen Turner [EMAIL PROTECTED] wrote:

 Fun-with-English question: Is a 'sandtrap' the normal US word
 for what we over here call a 'bunker'? Is 'bunker' also used?

Both are listed (sand trap is spelled with a space) in 
Webster's Ninth New Collegiate Dictionary and in The American 
Heritage Dictionary (3rd ed.).  There's no indication of a 
preference for either, and no indication that bunker is in 
any way un-American.

My only UK dictionary is the compact OED.  It lists bunker 
but not sand trap, and it says that bunker is Scottish.  
But then that part of the dictionary was written in the 1880s.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: TPR(0,1) scores

2002-03-02 Thread Keith C. Ivey

Jonathan E. Paton [EMAIL PROTECTED] wrote:

 Are you surprised bunker is a Scottish word?  Since we
 Scots invented golf, I guess we were entitled to attach our
 words to the game.

I'm not surprised that it was originally Scottish.  I was a 
little surprised that the OED considered the word (not just its 
origin) Scottish, since there was no indication of what the 
corresponding term would be in the English of England.  But 
perhaps English people didn't talk about golf in the 1880s.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: Fwd: Re: interesting typo I couldn't see

2002-02-22 Thread Keith C. Ivey

Rick Klement [EMAIL PROTECTED] wrote:

 I write it this way (corrected) (with tabs and TS=2 in vim):
 
 if (...)
   {
   my @item_parts = split(/\n/, $item);
   printf ORDER (\n%4d   %-50s   %3.2f  %3.2f\n,
 $quantity, $item_parts[0], $price, $ext);
   }
 else
   {
   printf ORDER (\n%4d   %-50s   %3.2f %3.2f\n,
 $quantity, $item, $price, $ext);
   }
 
 It makes the problem obvious... :)

Well, what I said was true.  I wasn't familiar with that style.
Perhaps I've led a sheltered life.  I guess you're right that 
it avoids the problem, as long as you never have more than one 
tab level of indenting for the second line of a statement.  But 
then if you never have a greatly indented second line (and thus 
never worry about lining things up), the problem won't be very 
likely regardless of your indenting style.

Since I have never encountered the problem and am quite happy 
with my own, standard indenting style, I see no reason to 
change.  But we're venturing into unfun territory.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: TPR0: the leaderboard...

2002-02-11 Thread Keith C. Ivey

Jerome Quelin [EMAIL PROTECTED] wrote:

 I remember you the fixed rules:
 - Number is to be taken as first arg of the script.
 - You can assume input as [0-9A-Z] (ie, no lowercase).

ASCII?  Or do the solutions have to work for EBCDIC as well?

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



RE: Golf and the Perl Review

2002-02-08 Thread Keith C. Ivey

Patrick Gaskill [EMAIL PROTECTED] wrote:

 As an aside, I'd say that in general I think of math problem
 golf holes as functions, and text mangling holes as
 file-suckers. At least it's something to consider for those who
 may be working on Games::Golf. :)

How are functions scored?  The number of characters between the 
{ and the }?

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: Golf and the Perl Review

2002-02-08 Thread Keith C. Ivey

Ton Hospel [EMAIL PROTECTED] wrote:

 mm, assuming a filter of lower case ascii input, nothing allowed
 to stderr, my first attempt is 44 I think.

I don't think lowercase is a safe assumption.  The contest said 

Convert a base 36 number, with the digits [0-9A-Z], to its
base 10 representation

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: even.pl solutions

2002-01-28 Thread Keith C. Ivey

Stephen Turner [EMAIL PROTECTED] wrote:

 -n $==$.1;$=^=7
 ...y*yuoeia***ord
 for/./g;$=||print50 ivey
 
 
 This one looks interesting, but I can't make it work. Is there a
 typo?

Yes, we've run into this before.  Some mail program along the 
way added a dot at the beginning of the second line, and then 
did it again in your message.  There should be only one dot 
there.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: Golf challenge: decode CETI message

2002-01-12 Thread Keith C. Ivey

Ilmari Karonen [EMAIL PROTECTED] wrote:

 Besides, aren't single quotes special for s/// and y/// anyway? 
 I think what Keith _really_ meant was tr[\0\xff][ @] or
 equivalent.

No, I was intending for the operation to be performed on the 
program Patrick had suggested (or my revision), not on the 
input file (which doesn't contain any \x00 or \xff).  So 
unless I'm missing something q(s'\x0\xff' @') was indeed what I 
meant, special meaning of single quotes and all.  That is, I 
wanted to change the part of the program that said 
q(tr,01\n,\x0\xff,d;) to q(tr,01\n, @,d;).

I have no explanation for my not changing 'tr' to 'y' (or for 
that matter not removing the 'x' in '\x0').  I hang my head in 
shame.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: Golf challenge: decode CETI message

2002-01-09 Thread Keith C. Ivey

Patrick Gaskill [EMAIL PROTECTED] wrote:

 My attempt, at 79 characters:
 $\=$/;undef$/;$_=;s/.{70}//s;tr,01\n,\x00\xff,d;
 print$1while/(.{1,127})\n?/g;

Are we doing this without command-line switches?  This should
do the same in 65 characters:

$\=$,=$/;$/=x;$_=;s/.{70}//s;tr,01\n,\x0\xff,d;print/.{1,127}/g

But s'\x0\xff' @' to make it shorter and more visible on my system.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: Interactive golf hole

2002-01-08 Thread Keith C. Ivey

Wesley Darlington [EMAIL PROTECTED] wrote:

 -p s/\s*(([^]*)|((\S*?)#.*)|(\S+))\s*/$2$4$5:/g,s/:+$/\n/

Is the third set of parens necessary?  Won't this do the same?

  -p s/\s*(([^]*)|(\S*?)#.*|(\S+))\s*/$2$3$4:/g,s/:+$/\n/

And from there you can cut it further to

  -p s/\s*(([^]*)|(\S*?)#.*|(\S+))\s*/$+:/g,s/:+$/\n/

It still has the problems with trailing null fields and xx.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



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

2001-12-07 Thread Keith C. Ivey

 --- Keith C Ivey - 22
 #! /usr/bin/perl -lp
 }{$_=7e10+$.,s$.$$

Looks like I was the only one who didn't use printf on this 
hole (other than Piers, but using $# is similar), and I was 
only one stroke short of the winners.

I'm surprised no one submitted anything with 0 x10, but I
guess those always end up too long.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



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

2001-11-30 Thread Keith C. Ivey

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?

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: 'vacation'

2001-11-27 Thread Keith C. Ivey

Scott R. Godin [EMAIL PROTECTED] wrote:

 I'm particularly interested in 'screening' the bulk-mail type
 messages that list me in their bcc: header so that my address
 does not show up in the from: or cc: address listings,

You're lucky that so much of your spam would be blocked by such 
a filter.  A lot of the spam I get nowadays actually has my 
address in the To: line.  Sometimes it's even disguised as a 
bounce message.

 Ideally, it should return the offending mail to postmaster@*
 (where * is the supposed 'from' address) to report the abuse,
 and include a full copy of the original message including
 headers (along with a nice terse little message regarding the
 laws involved).

Be very careful with any solution you implement.  For the vast 
majority of spam, the From: address has nothing to do with the 
real sender or any open relay used.  Complaining to the 
postmaster there just annoys a completely innocent person who's 
no doubt getting quite enough complaints from ignorant victims 
of the spammer.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: First CPAN Joke Module

2001-11-17 Thread Keith C. Ivey

Michael G Schwern [EMAIL PROTECTED] wrote:

 Here is an early reference (sorry for the awful URL)
 http://groups.google.com/groups?th=d8f2e19fb2209276seekm=MERLYN
 .95Apr4083526%40linda.teleport.comframe=off

No need for the awfulness.  Google URLs for threads work just 
fine with just the 'th' parameter:

http://groups.google.com/groups?th=d8f2e19fb2209276

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: isprint Golf Challenge

2001-11-16 Thread Keith C. Ivey

David Wheeler [EMAIL PROTECTED] wrote:

 Now, this seemed rather silly to me. I couldn't imagine that 
 it was efficient, and I generally like to look for reasons to 
 lose POSIX and its bloat. This is what I came up with:
 
   $str =~ s/([^ -~])/'\\' . sprintf(%03o, ord($1))/ge;

If you're serious about submitting a patch, you might note that 
perlre says

Note also that the whole range idea is rather unportable
between character sets--and even within character sets
they may cause results you probably didn't expect. A sound
principle is to use only ranges that begin from and end at
either alphabets of equal case ([a-e], [A-E]), or digits
([0-9]). Anything else is unsafe. If in doubt, spell out
the character sets in full. 

Your character class works only in ASCII.  So for correctness 
it's better to use the POSIX character class syntax.  The 
character class for nonprintable characters can be written as 
either [[:^print:]] or [^[:print:]] (see perlre).  
Unfortunately, it seems that that syntax requires Perl 5.6.1, 
so it might not be the most friendly thing to use in a module.
I assume that's why the authors went with POSIX.pm.

If you're interested only in golf, and don't care about those 
issues, you can eliminate several bytes easily:

$str=~s/[^ -~]/sprintf'\%03o',ord$/ge;

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: isprint Golf Challenge

2001-11-16 Thread Keith C. Ivey

Michael G Schwern [EMAIL PROTECTED] wrote:

 Hmmm, there seems to be a little problem:
 
 $ perl -wle 'print \n =~ /[[:cntrl:]]/ ? Yep : Nope'
 Yep
 $ perl -wle 'print \n =~ /[[:print:]]/ ? Yep : Nope'
 Yep
 $ perl -Mutf8 -wle 'print \n =~ /[[:print:]]/ ? Yep :
 Nope' Nope

I missed that when I was testing.  There's the same problem 
with \t, \f, and \r (ASCII 9, 12, and 13).  Perl seems to 
think that anything that matches \s is printable, rather than 
just space.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: Practical Perl Golf

2001-11-15 Thread Keith C. Ivey

Uri Guttman [EMAIL PROTECTED] wrote:

 #ifbar
 
 should be filtered out but isn't. you can only pass lines which
 start with exact cpp command tokens

But shouldn't we be filtering out lines like these?

#if.bar
#undef-foo

And for that matter this, and numerous other lines that don't 
match the syntax of cpp commands?

#define

If we're not cheating at all, the program has to be a LOT 
longer.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: Practical Perl Golf

2001-11-14 Thread Keith C. Ivey

Michael G Schwern [EMAIL PROTECTED] wrote:

 perl -ne $saw_bang++ if /^#!.*(perl|PERL)/; print if $saw_bang  (!/^\s*#/ ||
 /^\s*#\s*(include|define|if|ifdef|ifndef|else|elif|undef|endif)/) your_file

How about this?

perl -pe$_=''if 
1../^#!.*perl/i;/^\s*#\s*(include|define|if(n?def)?|el(se|if)|undef|endif)/||s/^\s*#.*//s

Still too long (107 characters), and I cheated on the 
/^#!.*(perl|PERL)/ part -- but then I think you're already 
cheating by not checking what follows the preprocessor 
keywords.  Anyway, the scalar range operator is the real 
contribution.  I'm sure further improvement is possible.

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC



Re: Practical Perl Golf

2001-11-14 Thread Keith C. Ivey

Michael G Schwern [EMAIL PROTECTED] wrote:

 Schuyler's got it down to:
 
 perl -ne
 '(/^\\s*[^#]|^\\s*#\\s*(include|define|(ifn?|un)def|else|elif|endif)/)print'

That leaves comment lines when there's whitespace before the #.
And why the parens around the regex?

-- 
Keith C. Ivey [EMAIL PROTECTED]
Washington, DC