我们有一个任务是将二进制文件中的一些字符串更改为小写(从mixed/ to /whatever)。相关的字符串是对其他文件的引用(它与我们从Windows迁移到linux作为服务器环境的升级有关,所以情况突然变得很重要)。我们已经编写了一个使用perl循环来完成此任务的脚本。我们有一个包含大约300个文件的目录(目录的总大小约为150M),所以它是一些数据,但不是很大的数据量。
下面的perl代码大约需要6分钟来完成这项工作:
for file_ref in `ls -1F $forms6_convert_dir/ | grep -v "/" | sed 's/\(.*
我有一个脚本,其中有一个$variable,它存储的文本行数未定。假设我把它命名为script.bash,它位于$HOME中:
#!/bin/bash
# commands on the beginning of my script
variable='Lorem Ipsum is simply dummied
text of the printing and
typesetting industry. Lorem Ipsum has been the
industry standard dummy text ever since the 1500s'
# comma
one.txt内容如下。
Hi this is the first line in a file one.txt
cooler:some default cooler string `/var/log/cooler_x86_64_someos8.4/config.cf'
doing good nice!
all is well
Hi this is the lastline in a file one.txt
预期产出
/var/log/cooler_x86_64_ubantu.8.24/config.cf
我需要如下所示
cat one.txt | grep cooler | sed
当我在命令行中尝试散列时(如下面的示例所示),我会得到语法错误。我也试过用胖逗号,但结果还是一样。有人能帮我吗?
perl -e "%hash_ex=(as,wdesadc,afcsdc,esvdfvzdfvfv,1,sd,34,34);print $hash_ex{'1'};"
syntax error at -e line 1, near "};"
Execution of -e aborted due to compilation errors.
perl -e "%hash_ex=('a' => 1 , &
我的bash脚本使用perl命令用另一个文件的内容替换文件中的变量。我觉得很标准,但我在这里真的很挣扎。
#/bin/bash
display_usage() {
echo -e "\nUsage: This script must be run with an environment parameter (file in directory env/)."
echo -e "Example: ./configureEnv <env parameter>\n"
}
# If no env argum
我有一个json,它是一个对象数组。
下面的代码工作得很好:
use JSON qw( decode_json );
# the contents of json are from the file jsonfile.json
my $data='[{...}]'; # omitted for clarity
@decoded = @{decode_json($data)};
print Dumper \@decoded;
但是,当我尝试将它作为一行程序从命令行运行时,它会中断。
下列任何一项工作均未完成:
cat jsonfil
我正在学习如何在chrome上使用Perl。当我试图在终端中输入一个变量时,它会给我这个输出。我知道如何使用文件运行代码,只是想看看我可以在终端中使用perl -e直接做些什么,而不是使用vim。如何输入并打印终端中的标量变量?
#code starts below
stepdeff@penguin:~$ perl -e $var = 10;
syntax error at -e line 1, near "="
Execution of -e aborted due to compilation errors.
stepdeff@penguin:~$ perl -e x =
我在理解Windows中perl的命令参数引用时遇到了问题。使用以下程序:
use strict;
use warnings;
use File::Find;
use File::Copy;
my $dir = shift;
die 'Usage: perl Folderize.pl <directory>' unless $dir;
die "$dir doesn't exist" unless -d $dir;
根据对目录使用单引号还是双引号,我会得到不同的结果。如果我用'perl script.pl 'H:\Tes
我对perl和一般编程都比较陌生。现在,我正在尝试更多地了解如何使两个perl脚本交互,以及如何了解父进程/子进程。为此,我编写了两个小perl脚本(a.pl和b.pl),以便更多地了解这些内容:
a.pl:
#!/usr/bin/env perl
use strict;
use warnings;
print "\npick a card, any card you want!\n>";
my $card = <STDIN>;
my @cmd = ('./b.pl');
push @cmd, $card;
system(@cmd);
pr
请有人解释一下,为什么perl不替换regexp:
root@machine08:~# VERSIONK8S='${VERSION_KUBERNETES:-1.23.3-00}'
# with sed as i want it
root@machine08:~# sed -e "s/^VERSIONK8S=.*/VERSIONK8S=${VERSIONK8S}/g" /root/coding/k8s-setup/allnodes_basic_setup.sh | grep ^VERSIONK8S=
VERSIONK8S=${VERSION_KUBERNETES:
在我的脚本中引用倒数第二行。由于某些原因,Perl不能访问变量$perlPort,我该如何解决这个问题呢?注意:$perlPort是一个bash变量,位于我的perl脚本之前
perl -e '
{
package MyWebServer;
use HTTP::Server::Simple::CGI;
use base qw(HTTP::Server::Simple::CGI);
my %dispatch = (
"/" => \&resp_hello,
);
sub handle_req
我想弄清楚为什么会这样:
$_='12+34';$x=1;
s/(\d+)(.)(\d+)/"\$x$2$2"/ee; # This is working, does $x++
print "x=$x \n"; # x=2
虽然情况并非如此:
$_='12+34';$x=1;
s/(\d+)(.)(\d+)/\$x$2$2/e; # This is NOT working
# Error message is :
# Scalar found where operator expect