[Edit][Create New]
[ IndexPage / ネットとプログラミング / CGI / 便利なスクリプト片(未整理) / get10lines.test.pl ]

get10lines.test.pl

#!/usr/local/bin/perl

use Benchmark;

foreach(1 .. 32){
	$org .= "$_ woiejfwoeifjoweijfowiejfowiejfowiejfoiwjeo\n";
}

$count = 10000;
$newlines = 22;

#use integer;

timethese($count, {'canada2' => q{
	$buf = $org;
	$newlines = -10 + $buf =~ tr/\n/\n/;
	$buf =~ s/(.*\n){$newlines}//;
}, 'ohzaki1' => q{
  $buf = $org;
  $buf = reverse $buf;
  $buf =~ /^((?:[^\n]*\n){11})/;
  chomp($buf = $1);
  $buf = reverse $buf;
}, 'ohzaki2' => q{
  $buf = $org;
  $pos = length $buf;
  foreach (1 .. 11) {
    $pos = rindex $buf, "\n", $pos;
    $pos--;
  }
  $buf = substr $buf, $pos + 2;
	#print "$buf--\n";
}});