fork download
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. my ($accumulator,$chat,$username,$chars,$timestamp);
  7.  
  8. my @output_lines = <STDIN>;
  9.  
  10. foreach (@output_lines)
  11. {
  12. $accumulator .= $_;
  13.  
  14. ($chat,$username,$chars,$timestamp) = $accumulator =~ m/(?im)^\s*(.+)\s+(\w+[-,\.]\w+)\s+(\d+)\s+([0-1]?\d\/[0-3]?\d\/[1-2]\d{3}\s+[0-2]?\d:[0-5]?\d\s?[ap]m)\s*$/;
  15. $chat =~ s/\s+$// if $chat; #remove trailing spaces
  16.  
  17. if ( $accumulator =~ /(?i)([0-2]?\d:[0-5]?\d\s?[ap]m)/ ) {
  18. print "SECTION matched\n";
  19. print "-"x70,"\n";
  20. print "$accumulator";
  21. print "-"x70,"\n";
  22. print "chat -> ${chat}\n";
  23. print "username -> ${username}\n";
  24. print "chars -> ${chars}\n";
  25. print "timestamp -> ${timestamp}\n\n";
  26. $accumulator = ''; # reset the line accumulator
  27. }
  28. }
  29.  
  30.  
Success #stdin #stdout 0s 6132KB
stdin
Hello Line1 FirstName.LastName 10 3/23/2011 2:46 PM

Hello Line2

                     Line2FirstName-LastName       8       7/17/2015 1:15 PM 
Line2Testing - 12323232323 Hello There

Hello Line3 Line3FirstName.LastName 8 3/21/2011 2:46 PM

Hello Line4

                     Line4FirstName-LastName       8       9/17/2015 1:20 PM
stdout
SECTION matched
----------------------------------------------------------------------
Hello Line1 FirstName.LastName 10 3/23/2011 2:46 PM
----------------------------------------------------------------------
chat -> Hello Line1
username -> FirstName.LastName
chars -> 10
timestamp -> 3/23/2011 2:46 PM

SECTION matched
----------------------------------------------------------------------

Hello Line2

                     Line2FirstName-LastName       8       7/17/2015 1:15 PM 
----------------------------------------------------------------------
chat -> Hello Line2
username -> Line2FirstName-LastName
chars -> 8
timestamp -> 7/17/2015 1:15 PM

SECTION matched
----------------------------------------------------------------------
Line2Testing - 12323232323 Hello There

Hello Line3 Line3FirstName.LastName 8 3/21/2011 2:46 PM
----------------------------------------------------------------------
chat -> Hello Line3
username -> Line3FirstName.LastName
chars -> 8
timestamp -> 3/21/2011 2:46 PM

SECTION matched
----------------------------------------------------------------------

Hello Line4

                     Line4FirstName-LastName       8       9/17/2015 1:20 PM----------------------------------------------------------------------
chat -> Hello Line4
username -> Line4FirstName-LastName
chars -> 8
timestamp -> 9/17/2015 1:20 PM