- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
一个愚蠢的问题,但它让我发疯!我有一个脚本可以删除 bvh 文件中的“胖”数据。 (Biovision Action 捕捉文件..)。工作正常,但它创建了一个双重扩展......(名称.bvh.bvh)我只需要一个扩展名(*.bvh,不是 *.bvh.bvh!!!)这是代码:
@files = <*.bvh>;
foreach $file (@files) {
open (OLD, $file) || die "Couldn´t open $file: $!\n";
open (NEW, ">$file.bvh") || die "Couldn´t open $file.bvh: $!\n";
while (<OLD>) {
$line = $_;
if (/Normal/) { while (<OLD>) { last if /}/; } $line => ""; }
if (/normalIndex/) { while(<OLD>) { last if /[]]/; } $line = ""; }
$line =~ s/[-+]?[0-9]\.[0-9]+e[+-][0-9]+/0/g;
$line =~ s/([-+]?[0-9]+\.[0-9]{2})[0-9]+/$1/g;
$line =~ s/0\.00/0/g;
$line =~ s/[ ]+/ /g;
$line =~ s/[\t]+/ /g;
$line =~ s/^ //g;
print NEW $line;
}
close OLD;
unlink ($file);
close NEW;
}
有什么帮助吗?谢谢!
最佳答案
@files = <*.bvh>;
这为您提供了具有 .bvh
扩展名的文件列表。所以它最终会包含如下内容:
('foo.bvh', 'bar.bvh', 'baz.bvh')
然后用这段代码遍历数组:
foreach $file (@files) {
...
}
每次循环,$file
都将包含您数组中的一个值。例如,在第一次迭代中,$file
将包含 foo.bvh
。
然后打开输入和输出文件:
open (OLD, $file) || die "Couldn´t open $file: $!\n";
open (NEW, ">$file.bvh") || die "Couldn´t open $file.bvh: $!\n";
由于 $file
包含 foo.bvh
,您的新文件(使用名称 "$file.bvh"
创建)将被称为 foo.bvh.bvh
。
天真的解决方法是从 open()
语句中删除 .bvh
:
# DON'T DO THIS
open (OLD, $file) || die "Couldn´t open $file: $!\n";
open (NEW, ">$file") || die "Couldn´t open $file.bvh: $!\n";
这将不起作用,因为您的旧文件和新文件现在将具有相同的名称,并且当您打开新文件进行写入时,它将截断文件并删除所有输入数据。
您有时需要重命名文件。最简单的方法是保留现有文件名,并在处理完每个文件后,将其重命名为原始名称。
# And then at the end of your loop
# Note that as you're copying the new file over the old one,
# there's no need to delete the old one.
close OLD;
close NEW;
rename("$file.bvh", $file);
关于perl - 如何在 perl 脚本中删除扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62423290/
我有一个 .crt 文件。打开那个文件,我看到它以开头 -----BEGIN CERTIFICATE----- 如何从这个文件生成这 2 个文件?: 以-----BEGIN CERTIFICATE R
我有一个文件被加载到 fd.ChosenName 并想知道是否有一个快速的解决方案,例如与 stringbuilder 相反的截断文件名(扩展名)以用于显示目的。因此,如果 fd.ChosenName
我的文件名如下:name1.csv,我想提取该字符串的两个子字符串。一种将 name1 存储在一个变量中,另一种将扩展名 csv 存储在另一个变量中,但不带点。 我一直在寻找是否有像 Java 的 i
我正在尝试找出一种方法来确定我在 struts2 应用程序中上传的文件的文件类型。我的应用程序可以读取 CSV 和 XML 文件并根据上传的文件类型执行操作。我将该文件作为“File”类的实例。该文件
如何使用 NLP/信息提取 (IE) 方法检测/找出首字母缩略词的含义(扩展名)? 我们希望检测自由文本中是否使用了单词或其首字母缩略词,并将其映射到相同的实体/标记。 大多数在线论文都是关于医学缩略
我正在编写一个 shell 脚本,该脚本需要改变其行为,并根据特定 X11 扩展的存在或不存在为被调用程序提供不同的选项。我有一个可行的解决方案,但我希望有一个更干净的解决方案。我愿意考虑一个简单的
我要查找文件名的扩展名,扩展名只能是3个字符。 有点像, filename = str(input("Please enter filename: ")) 然后我想执行一个任务来查找扩展名,如果扩展名
我正在开发一种文档管理系统。最终用户是企业级用户。 我目前仅检查并允许上传符合以下条件之一的文件: "png|jpe?g|gif|xls|doc|docx|csv|ppt|txt|pdf|rtf" 我
尝试将文件列表添加到 Jlist,然后过滤 JList 中的文件以仅返回 .txt 文件和固定字符长度。还尝试删除返回的文件路径,并仅在文件 JList 中显示文件名+扩展名。 到目前为止,除了删除文
File.py file = fields.Binary('File') @api.multi def get_file(self): if self.file: xsl_fi
我尝试使用导航 Controller 使我的应用程序处于纵向模式我收到此错误 iam usring Xcode7 and Swift 2 And Target System IOS 9.3 声明仅在文
这个问题在这里已经有了答案: Test whether a glob has any matches in Bash (22 个回答) 关闭去年。 您将如何使用 bash 判断目录中是否存在特定扩展名
我正在开发转换器服务,我使用 FFMPEG 转换视频。 我想检查输入文件,哪种真的是视频。 我使用以下命令并获取文件类型。但是如果文件已经被操作过就无法理解了: curl -s -o /dev/nul
我需要一个规则来添加 .html 扩展名,只要有“不”结尾的斜杠。 一个新客户最近更改了电子商务脚本,新版本以不同的方式处理 SEO,并更改了他们所有 16,000 多个产品链接。这在站点被重新索引之
我正在尝试使用 Kickstarter 进行扩展以覆盖页面的正常呈现,并呈现 PDF 文件。为此我使用 FPDF。但我不确定该怎么做。我尝试这样做,但没有成功: AddPage();
在寻找巴恩斯利蕨分形的实现时,我遇到了一个具有 .pde 扩展名的实现。哪种编程语言使用此扩展? Implementation Page 最佳答案 此代码来自Processing.org,一个基于Ja
Visual Studio Code (1.22.2) 提供了一个名为 .dockerfile 的文件扩展名。在保存对话框中。带有此扩展名的文件是什么? Dockerfile 包含在所有文档和示例中,
我正在为32位计算机编译一个应用程序,因为该应用程序的创建者将其设置为64位。我确保所有库和DLL都是32位的。但是,我在编译时遇到问题。当我使用sh make.sh进行编译时,当它进入GCC构建部分
当我将文件保存在 img/upload 文件夹中时,文件会以正确的文件扩展名保存。 但是,当我尝试下载该文件时,会附加一个 .htm 文件扩展名。 我怎样才能避免这种情况?我在下面添加了我的代码; V
GHC 有几种有用的语言 extensions用于机械派生各种常见的 Haskell 类型类(-XDeriveFunctor、-XDeriveFoldable、-XDeriveTraversable)
我是一名优秀的程序员,十分优秀!