繁体   English   中英

Perl system()调用转义了元字符

[英]Perl system() call escapes metacharacter

我的学生编写了一个简单的程序,该程序调用system来管理某些文件,但是由于某种原因,它在不应该转义*字符时转义了该字符。

#!/opt/anaconda3/bin/perl

# catfastq.pl

# the following 'use' just makes the script print warnings and controles variable scoping (i.e. I have to place 'my' before a new variable declaration)
use warnings;
use strict;

# define array of letters that you will use in the file names
my @letter = ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'X', 'Z');

# store full path to where fastq files are in 'readdir' variable
my $readdir = '/home/data/madzays/finch_data/firstrun';

# store name of output directory in 'outdir' variable
my $outdir = '/home/data/madzays/finch_data/firstrun/combined';

# make output directory if it doesn't exist already
if (!-d $outdir)
{
        if (!mkdir($outdir))
        {
                print STDERR "Couldn't create output directory\n";
                exit 1;
        }
}

# loop through each element of the 'letter' array (note that the element will be stored in the 'lib' variable)
foreach my $lib (@letter)
{
        # the system function executes a command just like if you were to type it in the bash terminal

        # concatenate R1 files
        system("cat ${readdir}/RSFV1${lib}*R1_001.fastq > ${outdir}/RSFV1${lib}_R1.fastq");

        # concatenate R2 files
        system("cat ${readdir}/RSFV1${lib}*R2_001.fastq > ${outdir}/RSFV1${lib}_R2.fastq");
}

exit;

这是输出:

cat:/home/data/madzays/finch_data/firstrun/RSFV1S*R2_001.fastq: No such file or directory 
cat:/home/data/madzays/finch_data/firstrun/RSFV1T*R1_001.fastq: No such file or directory 
cat:/home/data/madzays/finch_data/firstrun/RSFV1T*R2_001.fastq: No such file or directory 
cat:/home/data/madzays/finch_data/firstrun/RSFV1U*R1_001.fastq: No such file or directory 
cat:/home/data/madzays/finch_data/firstrun/RSFV1U*R2_001.fastq: No such file or directory

文件在那里(例如)

RSFV1S_S37_L005_R1.fastq  RSFV1S_S37_L005_R2.fastq  RSFV1S_S37_L006_R1.fastq  RSFV1S_S37_L006_R2.fastq  RSFV1S_S37_L007_R1.fastq  RSFV1S_S37_L007_R2.fastq

在此处输入图片说明 任何想法可能有什么问题吗?

Perl没有转义* 问题是sh找不到任何匹配项,只有找到匹配项时它才会展开*

$ echo fi*le
fi*le

$ touch file

$ echo fi*le
file

问题是您正在使用

system("cat ${readdir}/RSFV1${lib}*R1_001.fastq > ${outdir}/RSFV1${lib}_R1.fastq");

system("cat ${readdir}/RSFV1${lib}*R2_001.fastq > ${outdir}/RSFV1${lib}_R2.fastq");

什么时候应该使用

system("cat ${readdir}/RSFV1${lib}*001_R1.fastq > ${outdir}/RSFV1${lib}_R1.fastq");

system("cat ${readdir}/RSFV1${lib}*001_R2.fastq > ${outdir}/RSFV1${lib}_R2.fastq");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM