PukiWiki


ファイルの読み書き

_ ファイルの読み書き

_ C言語

_ Perl

#!/usr/bin/perl

open(FH, "<" . $ARGV[0]) or die("open");

while( $line = <FH>)
{
        print $line;
}

close(FH);
$ perl test.pl aaa

_ Python

>>> f = open('aaa', 'r')
>>> f.read()
'aaa\nbbb\nccc\n\n'
>>> f.close()
>>> f = open('aaa', 'r')
>>> f.readline()
'aaa\n'
>>> f.readline()
'bbb\n'
>>> f.readline()
'ccc\n'
>>> f.readline()
'\n'
>>> f.readline()
''
>>> f.readline()
''
>>> f = open('aaa', 'r')
>>> f.readlines()
['aaa\n', 'bbb\n', 'ccc\n', '\n']
>>>
>>> f = open('aaa', 'r')
>>> for line in f:
...     print line,
...
aaa
bbb
ccc

>>>

_ Ruby

 
Link: MenuBar(91d)
Last-modified: 2017-07-19 (水) 22:33:28 (91d)