无法在Perl中删除单词末尾的新行

无法在Perl中删除单词末尾的新行,perl,Perl,我的脚本如下: my $workItemCommentorURL = "https://almweb1.ipc.com/jts/users/sainis"; my $json_text= "curl -s -D - -k -b ~/.jazzcookies -o commentor.json -H \"Accept: application/x-oslc-cm*\" \"$workItemCommentorURL\""; my $content = `cat commentor.json`;

我的脚本如下:

my $workItemCommentorURL = "https://almweb1.ipc.com/jts/users/sainis";
my $json_text= "curl -s -D - -k  -b ~/.jazzcookies -o commentor.json -H \"Accept: application/x-oslc-cm*\" \"$workItemCommentorURL\"";
my $content = `cat commentor.json`;
my $WICommentCreator = `cat commentor.json | perl -l -ne '/<j.0:name>(.*)<\\/j.0:name>/ and print \$1'`;
print "NAME OF COMMENTOR  ************-> \"$WICommentCreator\"\n";
即Shalini Saini,然后是一条新的线路。 而不是

NAME OF COMMENTOR  ************-> "Shalini Saini"
为什么在Saini之后会有一行新代码,为什么引号会出现在下一行?如何修剪它?

简短回答:删除-l开关,因为它会导致打印在末尾有一个换行符

详细回答:不要使用shell命令在Perl内部运行Perl,这是非常冗余的。正常读取文件即可

use strict;
use warnings;

my $workItemCommentorURL = "https://almweb1.ipc.com/jts/users/sainis";
my $json_text= "curl -s -D - -k  -b ~/.jazzcookies -o commentor.json -H \"Accept: application/x-oslc-cm*\" \"$workItemCommentorURL\"";
my $content = do { 
    open my $fh, "<", "commentor.json" or die $!;
    local $/; <$fh>;
};
my ($WICommentCreator) = $content =~ /<j.0:name>(.*)<\/j.0:name>/;
print "NAME OF COMMENTOR  ************-> \"$WICommentCreator\"\n";
简短回答:删除-l开关,因为它会导致打印在末尾有一个换行符

详细回答:不要使用shell命令在Perl内部运行Perl,这是非常冗余的。正常读取文件即可

use strict;
use warnings;

my $workItemCommentorURL = "https://almweb1.ipc.com/jts/users/sainis";
my $json_text= "curl -s -D - -k  -b ~/.jazzcookies -o commentor.json -H \"Accept: application/x-oslc-cm*\" \"$workItemCommentorURL\"";
my $content = do { 
    open my $fh, "<", "commentor.json" or die $!;
    local $/; <$fh>;
};
my ($WICommentCreator) = $content =~ /<j.0:name>(.*)<\/j.0:name>/;
print "NAME OF COMMENTOR  ************-> \"$WICommentCreator\"\n";

简短回答:取下-l开关。只是想知道。当在5行脚本中调用3行shell程序时,为什么要使用perl。使用简单的bash不是更容易吗或者,如果您想使用perl,简单地先用3个命令调试一个bash脚本,然后用一个qx调用该脚本……从perl程序中调用perl显然是。。。次优:-/简短回答:移除-l开关。只是好奇。当在5行脚本中调用3行shell程序时,为什么要使用perl。使用简单的bash不是更容易吗或者,如果您想使用perl,简单地先用3个命令调试一个bash脚本,然后用一个qx调用该脚本……从perl程序中调用perl显然是。。。次优:-/