fork download
  1. #!/usr/bin/perl
  2. use 5.016;
  3. use warnings;
  4. use utf8;
  5. binmode STDOUT => ':encoding(utf-8)';
  6.  
  7. open(my $in, '<:encoding(utf-8)', \(my $dmy = <<'EOL')) or die;
  8. こういった10行で一組のデータの中に
  9. ---
  10. 市民の...
  11.  
  12. yerles
  13. warrior
  14. ---
  15. というパターンが多くあります。
  16. マッチ検索したいのは
  17. ---
  18. 市民の...
  19.  
  20. dog
  21. warrior
  22. ---
  23. というパターンです。
  24. "市民"という文字を見つけたら
  25. 2行下に
  26. "dog"という文字があるならば
  27. その、"市民の..."を出力して欲しいです。
  28. EOL
  29.  
  30. my @pipe = ('', '', '');
  31. while(<$in>){
  32. push(@pipe, $_);
  33.  
  34. if (/dog/ and $pipe[0] =~ /市民/){
  35. print $pipe[0], "\n";
  36. }
  37. }
  38. close($in);
  39.  
Success #stdin #stdout 0.02s 5012KB
stdin
Standard input is empty
stdout
市民の... 
"市民"という文字を見つけたら