code_junkie

what's the best way to parse a body of text against multiple (15+) regexes on each line?

Nov 12th, 2011
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. perldoc perlfaq6
  2.  
  3. perldoc perlfaq6
  4.  
  5. perldoc perlfaq6
  6.  
  7. while (<>) {
  8. chomp;
  9. PARSER: {
  10. m/ G( d+b )/gcx && do { print "number: $1n"; redo; };
  11. m/ G( w+ )/gcx && do { print "word: $1n"; redo; };
  12. m/ G( s+ )/gcx && do { print "space: $1n"; redo; };
  13. m/ G( [^wd]+ )/gcx && do { print "other: $1n"; redo; };
  14. }
  15. }
  16.  
  17. regex1|regex2|regex3|...|regex15
  18.  
  19. HAND_LINE: for ($Line)
  20. { /^*** ([A-Z ]+)/ and do
  21. { # parse the string that is captured in $1
  22. last HAND_LINE; };
  23. /^Dealt to (.+) [(.. ..)]$/ and do
  24. { # $1 contains the name, $2 contains the cards as string
  25. last HAND_LINE; };
  26. /(.+) folds$/ and do
  27. { # you get the drift
  28. last HAND_LINE; }; };
Add Comment
Please, Sign In to add comment