Re: Another one-liner?

2009-06-25 Thread yanick
On Wed, Jun 24, 2009 at 06:59:41PM +0200, Eirik Berg Hanssen wrote:
 yan...@babyl.dyndns.org writes:
  I'm probably overlooking something silly, but
 
  perl -O0 -pe's/.{65535,}//'  
  
  ?
 
   Newlines.

Arrgh.  I knew I was forgetting something. Darn, foiled again!

Joy,
`/anick

-- 


Re: Another one-liner?

2009-06-24 Thread Jasper
2009/6/24 Daniel Tiefnig dan...@gmx.at:

  perl -00 -ne'/.{65535}/||print'


of course becomes

perl -00 -pe'$_ x=!/.{65535}/'

-- 
Jasper


Re: Another one-liner?

2009-06-24 Thread Eirik Berg Hanssen
yan...@babyl.dyndns.org writes:

 On Wed, Jun 24, 2009 at 04:26:05PM +0100, Jasper wrote:
 2009/6/24 Daniel Tiefnig dan...@gmx.at:
 
  ?perl -00 -ne'/.{65535}/||print'
 
 
 of course becomes
 
 perl -00 -pe'$_ x=!/.{65535}/'

   I'm probably overlooking something silly, but

   perl -O0 -pe's/.{65535,}//'  
   
   ?

  Newlines.


Eirik
-- 
Perl programmers do it more than one way


Re: Another one-liner?

2009-06-24 Thread Daniel Tiefnig
Eirik Berg Hanssen wrote:
 I'm probably overlooking something silly, but
 
 perl -O0 -pe's/.{65535,}//'
 
 Newlines.

Besides that I'm getting Can't do {n,m} with n  m in regex for values
greater than 2^15 - 1 here.

br,
daniel


Re: Another one-liner?

2009-06-24 Thread Daniel Tiefnig
Phil Carmody wrote:
 I needed to remove blank-line-separated chunks of code from a text 
 file if those chunks contained any lines which were 'too long'.
[...]
 If you think how little it does, it's got to be one-linerable, no?

Here's one that does split on lines with whitespace too, but is much
less elegant than my first one:

  perl -0777 -F'(?=\n)\s*(?=\n)' -ane'/.{65535}/||print f...@f'

Maybe one can save one or the other stroke with a smarter solution of
the newline issue...

lg,
daniel


Re: Another one-liner?

2009-06-24 Thread Daniel Tiefnig
Phil Carmody wrote:
 I needed to remove blank-line-separated chunks of code from a text 
 file if those chunks contained any lines which were 'too long'.
[...]
 If you think how little it does, it's got to be one-linerable, no?

Should do the trick:

  perl -00 -ne'/.{65535}/||print'

lg,
daniel


Re: Another one-liner?

2009-06-24 Thread Philippe Bruhat (BooK)
On Wed, Jun 24, 2009 at 04:26:05PM +0100, Jasper wrote:
 2009/6/24 Daniel Tiefnig dan...@gmx.at:
 
   perl -00 -ne'/.{65535}/||print'
 
 
 of course becomes
 
 perl -00 -pe'$_ x=!/.{65535}/'
 

Did you notice that this (x=!) is a secret operator of the same family
as the screwdriver operators discovered by Dmitry Karasik and showed
some time ago (November 2007) on fwp.

Actually, Dmitry only showed three of them:

 This bunch, I think, can be appropriately named screwdriver operators:
 
-=! and -=!!- flathead
+=! and +=!!- phillips
*=! and *=!!- torx

When preparing my talk on the Perl secret operators for the last French
Perl Workshop (and hopelessly looking for nice pictures of screwdrivers),
I realized that, in real life, there are several types or cruciform
(or cross-head) screwdrivers. It had to be the same in Perl!

Ladies and gentlemen, it is my pleasure to introduce you to the fourth
screwdriver operator, the Pozidriv (http://en.wikipedia.org/wiki/Pozidriv):

   x=! and x=!!- pozidriv


This is a conditional set to empty string operator (the string
equivalent of the torx):

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


I hope you'll welcome it in your toolbox, like Jasper did.

-- 
 Philippe Bruhat (BooK)

 The fish most likely to be caught is the one with the biggest mouth.
(Moral from Groo The Wanderer #17 (Epic))