[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: regex question



On Sun, Apr 13, 2008 at 09:37:02AM +1000, Alex Samad wrote:
 
> this works
> perl -e 'while(<>){chomp ; next if ( /^\s*;/);  print "[$_]\n" if length
> $_ > 0}' sip.conf
> 
> or this
> perl -nle 'next if ( /^\s*;/);  print  if length $_ > 0' sip.conf
> 
> why doesn't the next force a read of a new line and thus a new $_, why
> do I have to check for length of $_

I don't know.  This looks like a prime example of why I hate regex (or
it hates me).  I'd do it the long way in python with readlines, discard
empty lines and slice off comments to create a sequence of cooked lines.  

Don't ask me how to do that in perl.

Don't get me wrong, the ability to do this in one-liners is certainly
powerful.  Sed and grep are also likely quite CPU efficient, but I
wouldn't call any of these lines readable.

Doug.


Reply to: