[CentOS] text processing problem with bash/perl

Fri Feb 13 17:17:09 UTC 2009
Dennis Kaptain <dkaptain at yahoo.com.mx>

> 

> # Put Perl in "paragraph mode"
> $/ = '';
> 
> # For each record ...

I love this list! Paragraph mode REALLY cleans things up. Although it worked, this makes my first attempt look really amateurish.
Be sure to put the definition of $/ inside a code block { } if you are using it inside a program or it will cause difficulties in other areas since it is defined in main and therefore used everywhere.

#! /usr/bin/perl -w
use strict;

# use this like ./p2 < in.txt > out.txt
# or cat file | ./p2 > out.txt

{
   local $/ = ''; # turn on paragraph mode
   while (<>) {
      if (/localhost/) {
         $_ =~ s/\/\*//;
         $_ =~ s/\*\///;
      }
      print "$_\n";
   }
}


__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
Regístrate ya - http://correo.yahoo.com.mx/