我一直试图了解下面提到的代码到底发生了什么.但我无法理解它.
$mode = (stat($filename))[2];
printf "Permissions are %04o\n", $mode & 07777;
Run Code Online (Sandbox Code Playgroud)
让我说我的$ mode值是33188
$ mode&07777产生一个值= 420
$模式值是十进制数?
为什么我们选择07777以及为什么我们要做一个按位和操作.我无法在这里取消逻辑.
我在我的机器上安装了5.14.2,但是当我尝试用say关键字执行print语句时,它给了我错误.
我已经使用use关键字使程序运行没有错误.
#!/usr/bin/perl
use feature ':5.10';
say "hello";
Run Code Online (Sandbox Code Playgroud)
与5.010相比,5.14.2是最新的,所以它应该默认启用所有这些功能吗?那么使用use关键字指定版本有什么意义呢?
我有一组html标签,要在选中它们时突出显示。我正在尝试使用jquery来做到这一点。但这似乎不起作用。
$(function () {
setNavigation();
});
function setNavigation() {
var path = window.location.pathname;
path = path.replace(/\/$/, "");
path = decodeURIComponent(path);
$(".nav a").each(function () {
var href = $(this).attr('href');
if (path.substring(0, href.length) === href) {
$(this).closest('li').addClass('active');
}
});
}Run Code Online (Sandbox Code Playgroud)
a {
color:#000;
text-decoration:none;
}
a:hover {
text-decoration:underline;
}
a:visited {
color:#000;
}
.nav {
padding:10px;
border:solid 1px #c0c0c0;
border-radius:5px;
float:left;
}
.nav li {
list-style-type:none;
float:left;
margin:0 10px;
}
.nav li a {
text-align:center;
width:55px;
float:left;
}
.nav li.active {
background-color:green; …Run Code Online (Sandbox Code Playgroud)我正在尝试执行此代码.令我困惑的是为什么这个比较在错误时没有返回任何值.这是这些比较运算符的默认行为吗?
my $output = (2 <= 1);
print "value=$output";
Run Code Online (Sandbox Code Playgroud)
undef当逻辑检查失败时,比较运算符是否会返回?
当我尝试安装Net :: SSH :: Expect perl模块时,我收到以下错误.
perl Makefile.PL
Warning: prerequisite Expect 1.14 not found.
Writing Makefile for Net::SSH::Expect
Writing MYMETA.yml
Run Code Online (Sandbox Code Playgroud)
我期待安装在我的ubuntu机器上.
expect version 5.45
Run Code Online (Sandbox Code Playgroud)
但是在尝试安装它时仍然会向我发出此警告.请指教.
下面的代码工作正常,但如果我替换push @array,{%hash},push @array,\%hash那么它没有.有人可以帮我理解差异.我相信{%hash}是指匿名哈希.这是否意味着匿名哈希的寿命比对命名哈希(\%hash)的引用要长.
use strict;
use warnings;
use Data::Dumper;
my @array;
my %hash;
%hash = ('a' => 1,
'b' => 2,
'c' => 3,);
push @array,{%hash};
%hash = ('e' => 1,
'f' => 2,
'd' => 3,);
push @array,{%hash};
print Dumper \@array;
Run Code Online (Sandbox Code Playgroud)
产量
$VAR1 = [
{
'c' => 3,
'a' => 1,
'b' => 2
},
{
'e' => 1,
'd' => 3,
'f' => 2
}
];
Run Code Online (Sandbox Code Playgroud)
更新 以下是我正在处理的实际代码.我认为在这种情况下,参考的副本是我认为唯一可行的解决方案.如果我错了,请纠正我.
use …Run Code Online (Sandbox Code Playgroud) 我在这里需要速度.我有一个500mb大小的csv文件(实际上有很多csv,但我现在只考虑一个)我需要阅读第3列并从中选择唯一的字符串.我测试了以下方法,我发现只有awk是最快的
使用perl:
在上述所有方法中,解析csv大约需要500秒.
但如果我尝试使用awk做同样的事情,它将在近10秒内完成.
我仍然在学习我的脚步在Perl,最近我的激情向人们看到它的散列的电源后,成长了很多.但是这个问题让我退缩了.这是unix工具占上风的perl的一些限制吗?
我知道Text :: CSV是处理csv文件的最佳方式.但速度是我关注的问题,我可以保证我的csv没有任何嵌入式逗号或其他问题,只有Text :: CSV可以处理.
更新:发现我的问题
my %hash;
my $file = $ARGV[0] or die "Need input CSV $!\n";
open(my $fh,'<',$file) or die "Could not open the $file $!\n";
while(my $line = <$fh>)
{
chomp($line);
my $field2=(split /|/, $line)[2]; #I missed to quote the pipe delimiter
$hash{$field2}++;
}
print "$_\n" for keys %hash;
Run Code Online (Sandbox Code Playgroud)
另一个更新:发布并修复
我的csv被'|'分隔 我错过了引用它们.因此,执行时间显着减慢,而且它产生的输出是错误的,我没有注意到.引用分隔符后,脚本能够在大约18秒内完成,当我使用@Borodin逻辑限制字段分割时,执行时间进一步减少.我能达到与awk相同的速度.
我仍然发现Text :: CSV方法较慢,因为我的文件可以使用默认的分割方法,我将继续使用它.
perl ×6
awk ×1
css ×1
html ×1
javascript ×1
jquery ×1
linux ×1
perl-module ×1
permissions ×1
stat ×1
unix ×1