Advertisement
cwchen

Parse text file with regex

Mar 23rd, 2016
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.41 KB | None | 0 0
  1. #!/usr/bin/perl -n
  2.  
  3. use feature qw(say);
  4. use English;
  5.  
  6. BEGIN {
  7.     my %h;
  8. }
  9.  
  10. if (/(\w\w_map) (\d)/) {
  11.     $map_action = $1;
  12.     $num = $2;
  13.     $h{$key}->{$map_action} = $num;
  14. }
  15. else {
  16.     chomp;
  17.     $key = $_;
  18.     $h{$key} = {};
  19. }
  20.  
  21. END {
  22.     for $m (keys(%h)) {
  23.         print "${m}:" . $RS;
  24.         for $n (keys(%{$h{$m}})) {
  25.             print "\t${n} " . $h{$m}->{$n} . $RS;
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement