我将如何在扩展名之前将文本附加到文件名?
例如,
open my $in, '<', $my_file or die $!;
open my $out, '>',"$my_file" or die $!;
$my_file 看起来像这样:
/this/is/my/directory/blahblah.txt/
我想将它附加在输出中,如下所示:
/this/is/my/directory/blahblah_new.txt
or
new_blahblah.txt
希望这是一个好的解释!谢谢你。
像这样使用正则表达式替换:
open my $in, '<', $my_file or die "Cannot open $my_file for reading: $!";
( my $out_file = $my_file ) =~ s{([.]txt)$}{_new$1};
open my $out, '>', $out_file or die "Cannot open $out_file for writing: $!";
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句