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