Here we can compare the syntax of these languages, how do they get file extension.
我们可以比较一下php, perl, ruby, bash, python的语法,同样的功能是如何实现的。
in PHP:
$ext = pathinfo($file_name, PATHINFO_EXTENSION);
in Perl:
my $ext = ($file_name =~ m/[^.]+$/)[0];
in Ruby:
ext = File.extname(file_name)
in Bash:
ext=${file_name#*.} name=${file_name%.*}
in Python:
import os ext = os.path.splitext(file_name)[1]





















Leave a Reply