Skip to content

Instantly share code, notes, and snippets.

@gypark
Created January 31, 2012 01:17
Show Gist options
  • Save gypark/1708008 to your computer and use it in GitHub Desktop.
Save gypark/1708008 to your computer and use it in GitHub Desktop.
이해할 수 없는 에러
sub split_string {
my ($str, $length) = @_;
my $chars = decode( $HttpCharset, $str );
my $first = substr( $chars, 0, $length );
my $last = substr( $chars, $length );
return ( encode( $HttpCharset, $first ), encode( $HttpCharset, $last ) );
}
# split_string 과 완전히 동일한 일을 하는데,
# 게다가 쉘에서 이 부분만 떼어내어 테스트하면 잘 되는데,
# CGI 내에서만은 substr outside of string 에러
sub split_string2 {
my ($str, $length) = @_;
my $chars = decode( $HttpCharset, $str );
my $first = encode( $HttpCharset, substr( $chars, 0, $length ) );
# 다음 라인에서 에러
my $last = encode( $HttpCharset, substr($chars,$length) );
# 위 라인을 아래와 같이 두 줄로 나눠서 실행하면 이건 또 잘 됨 -_-
# my $last = substr( $chars, $length );
# $last = encode( $HttpCharset, $last );
return ( $first, $last );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment