我在哈希散列中访问变量时遇到问题我不知道我做错了什么.调试hash%list1的值会给出一个undef,所以我无法得到我的值.
use strict ;
use warnings ;
my $text = "The, big, fat, little, bastards";
my $Author = "Alex , Shuman ,Directory";
my %hashes = {1,2,3,40};
my %count = ();
my @lst = split(",",$text);
my $i = 0 ;
my @Authors = split(",", $Author);
foreach my $SingleAuthor(@Authors)
{
foreach my $dig (@lst)
{
$count{$SingleAuthor}{$dig}++;
}
}
counter(\%count);
sub counter
{
my $ref = shift;
my @SingleAuthors = keys %$ref;
my %list1;
foreach my $SingleAuthor1(@SingleAuthors)
{
%list1 = $ref->{$SingleAuthor1};
foreach my …Run Code Online (Sandbox Code Playgroud) 我在文件中的数据如下所示,有多列:
A B
Tiger Animal
Parrot Bird
Lion Animal
Elephant Animal
Crow Bird
Horse Animal
Man Human
Dog Animal
Run Code Online (Sandbox Code Playgroud)
我想在列A中找到与列B中的不同条目对应的条目数.如果可能在R中,或者可能是perl脚本.
输出为:
Animal 5
Bird 2
Human 1
Run Code Online (Sandbox Code Playgroud)
此外,如果可能的话,找出列A中的条目是否已经重复列B中的不同条目
A B
Tiger Animal
Tiger Animal
Run Code Online (Sandbox Code Playgroud) 我想从perl one liner打印昨天的日期,当我在命令提示符下运行时,我得到以下错误.
perl -e 'use POSIX qw(strftime);
$now_string = strftime "%Y%m%d", localtime(time()-86400);
print $now_string';
Run Code Online (Sandbox Code Playgroud)
错误:
Can't find string terminator "'" anywhere before EOF at -e line 1.
Run Code Online (Sandbox Code Playgroud)
我的perl版本v5.14.2
一个简单的例子:
function! Foo()
echom 'Starting Foo'
let x = Bar(123) " Function does not exist so E117 occurs.
echom 'Nonetheless, this executes.'
endfunction
Run Code Online (Sandbox Code Playgroud)
如果发生任何错误,Vim 是否具有中止函数或脚本的机制——换句话说,与bash.
set -o errexit
Run Code Online (Sandbox Code Playgroud)
澄清一下,我了解如何在try-catch. 我正在寻找一种通用机制来让 Vim 脚本的行为类似于 Python、Ruby、Perl 等语言,在这些语言中,未处理的错误会导致执行停止。
我在我的驱动器中有一个名为"Lib"的文件夹,里面包含很多文件,我有一个问题,这个"Lib"文件夹在驱动器的许多其他位置.我的Perl脚本必须复制最新更新的文件夹"Lib"中的内容并将其粘贴到"d:\ perl\Latest_copy_of_Lib"文件夹中
例如,我有一个库文件夹d:\functions,d:\abc和许多其他地方.我想在这些目录中找到每个文件的最新副本.因此,如果文件d:\functions\foo.txt是在2009-10-12上次修改并且在2009-10-13 d:\abc\foo.txt上次修改,那么我希望将版本中d:\abc的内容复制到目标目录.
我使用了file :: find但它在整个目录中搜索并复制了不是最新副本的内容.
我需要从多行字符串中提取文本(字符和数字).我尝试过的所有内容都没有删除换行/回车.
这是有问题的字符串:
"\r\n 50145395\r\n "
Run Code Online (Sandbox Code Playgroud)
在HEX中它是:0D 0A 20 20 20 20 20 20 20 20 35 30 31 34 35 33 39 35 0D 0A 20 20 20 20
我尝试过以下方法:
$sitename =~ m/(\d+)/g;
$sitename = $1;
Run Code Online (Sandbox Code Playgroud)
和
$sitename =~ s/^\D+//g;
$sitename =~ s/\D+$//g;
Run Code Online (Sandbox Code Playgroud)
和
$sitename =~ s/^\s+//g;
$sitename =~ s/\s+$//g;
Run Code Online (Sandbox Code Playgroud)
在所有情况下,我都无法摆脱任何不需要的角色.我在cygwin perl和Strawberry perl中运行了这个.
谢谢.