我已经使用Data::Dumper了很长时间.在谷歌搜索时,我发现了一个类似的模块Data::Dump.
任何人都可以告诉我,他们提供的子程序之间的主要区别是什么?
我正在运行脚本 A,它将包含文件路径的 ARGV 提供给 perl 脚本 B。这是由
local @ARGV = ($file, $file2, etc.);
do scriptB.pl or die "scriptB has failed";
Run Code Online (Sandbox Code Playgroud)
脚本 B 然后尝试打开文件:
open( my $fh_file, "<", $file )
or die "Could not open file '$file' $!";
Run Code Online (Sandbox Code Playgroud)
但是,如果文件丢失,我不会在 B 中的“or die”之后收到消息。而是在 A 中收到 do scriptB.pl or die 消息。如果我从 A 中删除“or die”,脚本将继续在 B 默默地死去之后,好像什么都没发生一样。
我想知道有没有办法让 B 打印它的死亡信息?
更好的是,让 B 在无法打开文件后运行代码块的最佳方法是什么?例如,所述代码将写入一个单独的文件,列出哪些文件丢失,以便用户可以轻松地追踪此类错误。
#something like
open( my $fh_file, "<", $file) or {
print "the file could not be found";
die;
}
Run Code Online (Sandbox Code Playgroud)
我在网上搜索帮助时发现的唯一一件事是有人提到了“or do {}”,但这给了我奇怪的语法错误,所以我不确定我是否正确使用它。
@tools = ("hammer", "chisel", "screwdriver", "boltcutter",
"tape", "punch", "pliers");
@fretools =("hammer", "chisel", "screwdriver" ,"blade");
push @tools,@fretools if grep @tools,@fretools
Run Code Online (Sandbox Code Playgroud)
我得到了工具
@tools=("hammer", "chisel", "screwdriver", "boltcutter",
"tape", "punch", "pliers", "blade");
Run Code Online (Sandbox Code Playgroud)
有什么简单的方法吗?
我在bash中使用expect.我希望我的脚本telnet到一个框中,期待一个提示,发送一个命令.如果现在有不同的提示,则必须继续,否则它必须再次发送该命令.我的脚本是这样的:
\#!bin/bash
//I am filling up IP and PORT1 here
expect -c "
set timeout -1
spawn telnet $IP $PORT1
sleep 1
send \"\r\"
send \"\r\"
set temp 1
while( $temp == 1){
expect {
Prompt1 { send \"command\" }
Prompt2 {send \"Yes\"; set done 0}
}
}
"
Run Code Online (Sandbox Code Playgroud)
输出:
invalid command name "while("
while executing
"while( == 1){"
Run Code Online (Sandbox Code Playgroud)
请帮助我.
我试着改变它 while [ $temp == 1] {
我仍然面临以下错误:
输出:
invalid command name "=="
while executing
"== 1"
invoked from within …Run Code Online (Sandbox Code Playgroud) 以前我在"有效Perl编程"一书中阅读了相关内容,但并没有真正理解它.今天,我遇到了一个问题,如下面的代码.
my $vname = "a";
my @a = qw(1 2 3);
local @array = @$vname;
foreach(@array) { print "$_\n"; };
Run Code Online (Sandbox Code Playgroud)
它什么都没输出.然后我修改了这一行:
local @a = qw(1 2 3);
Run Code Online (Sandbox Code Playgroud)
刚用"本地"替换"我的",那么现在就可以了.所以我想弄清楚它们之间有什么区别.
我在Tcl中有一个列表:
set list1 {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9}
Run Code Online (Sandbox Code Playgroud)
那我怎么能得到基于列表索引的元素?例如:
我想得到这个列表的第二个元素?或者这个清单的第六个?
需要一些好人帮我阅读扩展名为"xlsx"的excel文件我的脚本适用于"xls"但不适用于"xlsx",这里是我得到错误的代码:Can't call method "worksheet" on an undefined value如果文件是"xlsx",这里是我做的代码有:
#!/usr/bin/perl -w
use warnings;
use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::XLSX;
use Date::Format;
my $filename = "../test.xlsx";
#Parse excel file
my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse("$filename");
#Get cell value from excel sheet1 row 1 column 2
my $worksheet = $workbook->worksheet('Sheet1');
my $cell = $worksheet->get_cell(0,1);
# Print the cell value when not blank
if ( defined $cell and $cell->value() ne "") {
my $value = $cell->value();
print "cell value is …Run Code Online (Sandbox Code Playgroud) 我想在我的Mac上创建SQL数据库,我想知道什么是我可以创建/操作它的最佳软件.
任何建议将受到高度赞赏.
有谁知道如何在 Laravel 中使用 OUT 参数调用 MySQL 存储过程?
\n\n让\xe2\x80\x99s 说我有:
\n\nDB::statement('CALL sp_user_add(:name, :email, :password, :key, @res, @id);',\n array(\n $name,\n $email,\n $password,\n $key\n )\n);\nRun Code Online (Sandbox Code Playgroud)\n\n如何获取@res和的值@id?
为什么这不起作用?
my $myHashEncoded = encode_json \%myHash;
my %myHashDecoded = decode_json($myHashEncoded);
Run Code Online (Sandbox Code Playgroud)
我收到错误:
Reference found where even-sized list expected at ...
Run Code Online (Sandbox Code Playgroud)
所以我改成了:
my $myHashEncoded = encode_json \%myHash;
my $myHashDecoded = decode_json($enableInputEncoded);
Run Code Online (Sandbox Code Playgroud)
但后来显然%myHash不一样了$myHashDecoded.
如何从JSON字符串恢复正确的哈希?