ForNext
Only Do What Only You Can Do
188. in memory file
Hyperpolyglot Interpreted Languages: PHP, Perl, Python, Ruby より (2012.05.08)
VBScript
JScript
Perl
my ($f, $s); open($f, ">", \$s); print $f "lorem ipsum\n"; $s;
PHP
$meg = 1024 * 1024; $mem = "php://temp/maxmemory:$meg"; $f = fopen($mem, "r+"); fputs($f, "lorem ipsum"); rewind($f); $s = fread($f, $meg);
Python
from StringIO import StringIO f = StringIO() f.write('lorem ipsum\n') s = f.getvalue() Python 3 moved StringIO to the io module
Ruby
require 'stringio' f = StringIO.new f.puts("lorem ipsum") f.rewind s = f.read