保存Temp Word Perl单引号

问题描述

| 我试图用单引号将hello world保存在临时文件中 我打开没有单引号的hello world临时文件显示 如何解决这个问题
#!/usr/bin/perl -w
chomp($TMPFILE = `mktemp bumatinaskk.XXXXXXXXXX`);
$echo = \"echo \\\'hello word\\\' >>$TMPFILE\";
system (\"$echo\");
    

解决方法

        
use 5.010;
use strict;
use warnings FATAL => \'all\';
use autodie;
use File::Temp qw(tempfile);
use IO::File qw();

my ($file_handle,$file_name) = tempfile(\'bumatinaskk.XXXXXXXXXX\',UNLINK => 1);
$file_handle->say(q{\'hello world\'});
$file_handle->close;
say \"wrote into temporary file $file_name\";

sleep 30;   # giving you some time to inspect the temporary file

END { say \'temporary file is going to be deleted now\' }
文档:File :: Temp,IO :: File     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...