Re: text processing problem with bash/perl

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



> 

> # 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/ 
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos


[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux