Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 10th, 2012  |  syntax: Perl  |  size: 1.75 KB  |  hits: 41  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/perl
  2. eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
  3.     if $running_under_some_shell;
  4.                         # this emulates #! processing on NIH machines.
  5.                         # (remove #! line above if indigestible)
  6.  
  7. eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift;
  8.                         # process any FOO=bar switches
  9.  
  10. $[ = 1;                 # set array base to 1
  11. $, = ' ';               # set output field separator
  12. $\ = "\n";              # set output record separator
  13.  
  14. $state = 0;
  15. $temp1 = "";
  16. $temp2 = "";
  17. $musr = qr/\(-,user3,[^,]+\.co\.uk\)\\$/;
  18. $lusr = qr/\(-,user3,[^,]+\.co\.uk\)$/;
  19. $strprn="";
  20.  
  21. while (<>) {
  22.     chomp;      # strip record separator
  23.  
  24.     if (($state == 0) && ($_ !~ $musr) && ($_ !~ $lusr)) {
  25.         if (length($temp1) != 0) {
  26.             print $temp1;
  27.         }
  28.  
  29.         $temp0 = $_;
  30.         $state = 1;
  31.     }
  32.     elsif (($state == 1) && ($_ !~ $musr) && ($_ !~ $lusr)) {
  33.         if (length($temp0) != 0) {
  34.             print $temp0;
  35.         }
  36.  
  37.         $temp1 = $_;
  38.         $state = 0;
  39.     }
  40.     elsif (($state == 0) && ($_ =~ $musr)) {
  41.         $state = 2;
  42.     }
  43.     elsif (($state == 2) && ($_ =~ $musr)) {
  44.         $state = 3;
  45.     }
  46.     elsif (($state == 3) && ($_ !~ $musr) && ($_ !~ $lusr)) {
  47.         print $temp1;
  48.         print $_;
  49.         $temp1 = "";
  50.         $temp0 = "";
  51.         $state = 1;
  52.     }
  53.     elsif (($state == 2) && ($_ =~ $lusr)) {
  54.         $strprn=substr($temp1, 0, length($temp1) - 1);
  55.         print $strprn . "\n";
  56.         $temp1 = "";
  57.         $state = 0;
  58.     }
  59.     else {
  60.         print "Error at line " . $.; exit $.;
  61.     }
  62. }
  63.  
  64. if ($state == 0) {
  65.     print $temp1;
  66. }
  67. elsif ($state == 1) {
  68.     print $temp0;
  69. }
  70. else {
  71.     exit $.;
  72. }
  73.  
  74. #exit $ExitValue;