我正在运行perl,为sun4-solaris-64int构建的v5.6.1
我在数组上调用print:
print "@vals\n";
Run Code Online (Sandbox Code Playgroud)
输出看起来像:
HASH(0x229a4) uid cn attuid
Run Code Online (Sandbox Code Playgroud)
或者另一个例子:
@foo = {};
push(@foo, "c");
print "@foo I am done now\n";
Run Code Online (Sandbox Code Playgroud)
输出:
HASH(0x2ece0) c I am done now
Run Code Online (Sandbox Code Playgroud)
HASH(0x2ece0)
来自哪里?
在我的Perl代码中,我使用了以下行:
$host=$hostname if ($host eq undef);
Run Code Online (Sandbox Code Playgroud)
在输出中我得到以下消息:
Use of uninitialized value $host in string eq at cli.pl line 18.
Run Code Online (Sandbox Code Playgroud)
虽然我没有使用strict
.如何避免在输出上打印此消息?
if ( $2 && $3 && $3 != 0 )
Run Code Online (Sandbox Code Playgroud)
Perl中的上述逻辑是什么?在其他语言中,我从未见过像这样的if条件.2美元和3美元只是捕获一些正则表达式的组.
或这个:
if ( $2 && $2 == 0 && $3 && $3 == 0 )
Run Code Online (Sandbox Code Playgroud) perl -pi.back -e 's/2013/07/31-05:54:14/2014/07/31-00:00:00/g;' /tmp/ranjan/replace.SEL
Run Code Online (Sandbox Code Playgroud)
我使用上面的一个衬垫从更换之日起2013/07/31-05:54:14
对2014/07/31-00:00:00
.但我无法做到.我只能找到字符串的替换而不是上述格式的数字.请帮帮我.
我想要做:
curl -X DELETE -d '{"name":"flowx"}' 'http://somewhere/wm/staticflowentrypusher/json'
Run Code Online (Sandbox Code Playgroud)
在 Perl 中:
my $browser = LWP::UserAgent->new;
my $url = 'http://somewhere/wm/staticflowentrypusher/json';
$browser->delete($url, '{"name":"flowx"}');
Run Code Online (Sandbox Code Playgroud)
但我得到:
Illegal field name '{"name":"flowx"}' at /home/user/perl5/lib/perl5/HTTP/Request/Common.pm line 115
Run Code Online (Sandbox Code Playgroud) 我有一个Perl DBI语句
my $sql_statement = "select c.* ".
"from meter_category c ".
"where c.category = ".$current_category." ".
"and c.effective_date <= ".
$DBHdl->quote($time_stamp)." ".
"and c.meter_size = ".$meter_size." ".
"order by c.effective_date desc ; ";
Run Code Online (Sandbox Code Playgroud)
$DBHdl
是一个Informix数据库句柄.
声明如下:
select c.*
from meter_category c
where c.category = 1
and c.effective_date <= '09/20/2013'
and c.meter_size = 0.63
order by c.effective_date desc ;
Run Code Online (Sandbox Code Playgroud)
在我的函数中的某个时刻,我想设置$current_category
为2,然后修改$ sql_statement.
后
$current_category = 2;
eval $sql_statement
Run Code Online (Sandbox Code Playgroud)
不会改变$ sql_statement,所以c.category = 2
.
有没有办法执行替换,还是我必须重新发布声明?
我使用以下代码为$ current_category的每个值准备和执行查询.
my $ptSelHdl …
Run Code Online (Sandbox Code Playgroud) 在以下示例中,@DAYS
是月份的日期和条目@DAYS_SINCE_RAIN
对应于条目@DAYS
,例如$DAYS_SINCE_RAIN[4]
,自上次下雨以来的天数$DAYS[4]
.
在@DAYS_SINCE_RAIN
,有雨的那一天的值为0.我想要出现0的最后一个实例.
#iii. Find the last day of rain in April 2013.
print "#iii. Find the last day of rain in April 2013.\n";
$i=0;
@getday=();
while(@DAYS_SINCE_RAIN[$i]=~ m/0/){
push @getday, @DAY[$i];
$i++;
if($i=$#DAYS_SINCE_RAIN){
last;
}
};
print "@DAYS_SINCE_RAIN";
print "\n day of last rain: @getday[$i] ";
Run Code Online (Sandbox Code Playgroud)
似乎没有存储任何值:(
我的命令:
system("start cmd.exe /k C:\\script.pl $arg1 $arg2 $arg3");
Run Code Online (Sandbox Code Playgroud)
没有正确传递参数.这样做的正确方法是什么?
谢谢
我想将表单的sting转换为1,2,25-27,4,8,14,7-10
实际值的列表:1,2,4,7,8,9,10,14,25,26,27
.
我搜索过,发现没有做这种扩展的事情.任何人都知道如何轻松地做到这一点?
如何在Perl中自动输入密码?
码:
my $makecmd .= system "ssh remotehost;";
system( "$makecmd" );
Run Code Online (Sandbox Code Playgroud)
输出:
Enter passphrase for key '~/.ssh/id_rsa':
Run Code Online (Sandbox Code Playgroud)