我正在尝试编写一些获取文件内容并将其附加到另一个文件的内容。
if($x == 1) {take the contents of ./machines/x.txt and append to ./$engineer.txt;}
if($y == 1) {take the contents of ./machines/y.txt and append to ./$engineer.txt;}
if($z == 1) {take the contents of ./machines/z.txt and append to ./$engineer.txt;}
这里有很多关于附加的内容,但我无法使其与我的脚本一起使用。
提前致谢。
Path::Tiny
模块 会很容易,因为它包含附加到文件和获取文件内容的方法:
#!/usr/bin/env perl
use warnings;
use strict;
use Path::Tiny; # Install with your OS package manager or favorite CPAN client
path("file1.txt")->append_raw(path("file2.txt")->slurp_raw);