这个问题是关于Devel::NYTProf探查者的.
我从分析器接收到的简单行的输出,例如:
use strict;
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
statements: 3
Time on Line: 22µs
Calls: 2
Time in Sub: 12µs
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:
先感谢您
我在两个不同的模块中使用 SHA 256 哈希生成器。一个模块是用 Kotlin 编写的,另一个模块使用 Nodejs 加密 API 编写。Nodejs 和 kotlin 中的哈希值略有不同。
Kotlin 代码
import java.security.MessageDigest
import java.util.Base64
fun main() {
val md = MessageDigest.getInstance("SHA-256")
val input = "test".toByteArray(Charsets.UTF_8)
val bytes = md.digest(input)
println(Base64.getUrlEncoder().encodeToString(bytes))
}
Run Code Online (Sandbox Code Playgroud)
Nodejs代码
const crypto = require('crypto');
const hash = crypto.createHash('sha256');
hash.update('test');
console.log(crypto.createHash('sha256').update('test', 'utf8').digest('base64'));
Run Code Online (Sandbox Code Playgroud)
kotlin 代码输出n4bQgYhMfWWaL-qgxVrQFaO_TxsrC4Is0V1sFbDwCgg=where ,而 Nodejs 代码输出n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg=。我无法确定我做错了什么?
更新5-10-2013
好的,现在我可以毫无问题地过滤掉IP地址了。现在来我想做的接下来的三件事,我认为可以轻松完成sort($keys),但是我错了,然后尝试使用下面稍微复杂一点的方法也不是解决方案。我需要完成的下一件事是收集日期和浏览器版本。我将提供一个示例,说明我的日志文件和当前代码的格式。
预约日志
24.235.131.196 - - [10/Mar/2004:00:57:48 -0500] "GET http://www.google.com/iframe.php HTTP/1.0" 500 414 "http://www.google.com/iframe.php" "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)"
Run Code Online (Sandbox Code Playgroud)
我的密码
#!usr/bin/perl -w
use strict;
my %seen = ();
open(FILE, "< access_log") or die "unable to open file $!";
while( my $line = <FILE>) {
chomp $line;
# regex for ip address.
if( $line =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/ ) {
$seen{$1}++;
}
#regex for date an example is [09\Mar\2009:05:30:23]
if( $line =~ /\[[\d]{2}\\.*[\d]{4}\:[\d]{2}\:[\d]{2}\]*/) {
print "\n\n $line matched : $_\n"; …Run Code Online (Sandbox Code Playgroud) 我已经$^I在perl脚本中用于有条件地搜索和替换.我想知道是否$^I在缓冲区中复制文件并在处理缓冲区后将整个缓冲区写回文件,或者在行编辑中.
代码如下
$^I = "";
my $flag = 0;
while ($line = <>) {
if($line=~ m/some string/i) {
$flag = 1;
}
if(!$flag) {
$line =~ s/string/replace/g;
}
}
print $line;
Run Code Online (Sandbox Code Playgroud) 好的,这是一个N00b问题,但它让我感到难过:
我有以下Perl代码:
%project_keys = (
cd => "continuous_delivery",
cm => "customer_management",
dem => "demand",
dis => "dis",
do => "devops",
sel => "selection",
seo => "seo"
);
print "proj_code is $proj_code\n";
while ( ($key, $value) = each %project_keys ) {
if ($key == $proj_code) {
$url = "http://projects/".$project_keys{$key}."/setter";
last;
}
}
Run Code Online (Sandbox Code Playgroud)
$proj_code始终传递相同('dis'),打印行显示.
但是,每次我运行它,我都会获得不同的值project_keys{$key}.
什么(毫无疑问是显而易见的)我做错了什么?我看过关于每个人如何"脆弱"的评论 - 是吗?
我正在尝试实现二进制搜索.这是我的代码:
#!/usr/bin/perl
#use strict;
use warnings;
@array = (1..100);
$number = <STDIN>;
$low = 0;
$high = $#array;
while($low < $high){
print "Searcing $low ---- $high \n";
$mid = $low + ($high - $low)/2;
if($array[$mid] == $number){
print "Found in index:" . $mid;
last;
}
elsif($array[$mid] < $number){
$low = $mid + 1;
}
else{
$high = $mid - 1;
}
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用,虽然它是一个直接的实现(至少它将在Java中).
似乎我在分割时得到浮点值并且无法搜索.如果我提供输入,5我会得到垃圾:
5
Searcing 0 ---- 99
Searcing 0 ---- 48.5
Searcing 0 ---- 23.25
Searcing …Run Code Online (Sandbox Code Playgroud) 是DBI在Perl中访问数据库的唯一方法吗?
除了DBI可用之外还有其他任何可用于访问数据库的包装器MS-SQL/Oracle/MySQL.
我跟随两个用perl编写的语句:
@m1 = ( [1,2,3],[4,5,6],[7,8,9] ); # It is an array of references.
$mr = [ [1,2,3],[4,5,6],[7,8,9] ]; # It is an anonymous array. $mr holds reference.
Run Code Online (Sandbox Code Playgroud)
当我尝试print:
print "$m1[0][1]\n"; # this statement outputs: 2; that is expected.
print "$mr->[0][1]\n"; #this statement outputs: 2; that is expected.
print "$mr[0][1]\n"; #this statement doesn't output anything.
Run Code Online (Sandbox Code Playgroud)
我觉得第二和第三印刷语句是一样的.但是,我没有输出第三个print语句.
谁能让我知道第三次印刷声明有什么问题?
我继承了一个脚本,我需要能够从哈希中访问一些数据.我希望能够从以下访问MB_Path值.
$VAR1 = bless(
{
'ME_Parts' => [
bless(
{
'ME_Bodyhandle' => bless(
{
'MB_Path' => '/tmp/msg-15072-1.txt'
},
'MIME::Body::File'
),
'ME_Parts' => [],
'mail_inet_head' => bless(
{
'mail_hdr_foldlen' => 79,
'mail_hdr_modify' => 0,
'mail_hdr_list' => [
'Content-Type: text/plain; charset="us-ascii"',
'Content-Transfer-Encoding: quoted-printable'
],
'mail_hdr_hash' => {
'Content-Type' => [
\$VAR1->{'ME_Parts'}[0]{'mail_inet_head'}
{'mail_hdr_list'}[0]
],
'Content-Transfer-Encoding' => [
\$VAR1->{'ME_Parts'}[0]{'mail_inet_head'}
{'mail_hdr_list'}[1]
]
},
'mail_hdr_mail_from' => 'KEEP',
'mail_hdr_lengths' => {}
},
'MIME::Head'
)
},
'MIME::Entity'
),
bless(
{
'ME_Bodyhandle' => bless(
{
'MB_Path' => '/tmp/msg-15072-2.html'
}, …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个Perl程序来确定7个字符的用户输入是否是回文.
不使用任何数组,字符串或反向函数.
期望的输出:
Enter in a 7 character item: 1111111
PALINDROME!
Run Code Online (Sandbox Code Playgroud)
要么
Enter in a 7 character item: 1234567
NOT A PALINDROME!
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止:
print "Enter in a 7 character item: \n";
my ($a, $b, $c, $d, $e, $f, $g);
chomp ($a=<>); chomp ($b=<>); chomp ($c=<>); chomp ($d=<>);
chomp ($e=<>); chomp ($f=<>); chomp ($g=<>);
if ($a~~$g && $b~~$g && $c~~$e){
print "PALINDROME!\n";
}
else{
print "NOT A PALINDROME! \n";
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这给了我这个结果:
Enter in a 7 character item:
1
1
1
1 …Run Code Online (Sandbox Code Playgroud)