Skip to content

Instantly share code, notes, and snippets.

@backroot
Created August 27, 2015 05:39
Show Gist options
  • Save backroot/242af45bc22e9df3877c to your computer and use it in GitHub Desktop.
Save backroot/242af45bc22e9df3877c to your computer and use it in GitHub Desktop.
ファイルの読み込み
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