Created
August 27, 2015 05:39
-
-
Save backroot/242af45bc22e9df3877c to your computer and use it in GitHub Desktop.
ファイルの読み込み
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub readFile{ | |
my $path = shift; | |
my( $ret, @ret); | |
open( FH, "<".$path); | |
if( wantarray){ | |
push( @ret, $_) foreach( <FH>); | |
}else{ | |
my $retcode = $/; | |
undef( $/); | |
$ret = <FH>; | |
$/ = $retcode; | |
} | |
close( FH); | |
# UTF-8のBOMがあれば削除 | |
$ret =~ s/^\xEF\xBB\xBF//is; | |
$ret[ 0] =~ s/^\xEF\xBB\xBF//is if( scalar( @ret)); | |
return ( wantarray) ? @ret: $ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment