小编Dav*_*oss的帖子

存在和定义之间有什么区别?

有什么区别

if (defined $hash{$key}) { }
Run Code Online (Sandbox Code Playgroud)

if (exists $hash{$key}) { }
Run Code Online (Sandbox Code Playgroud)

我什么时候知道使用哪个?

perl

59
推荐指数
3
解决办法
5万
查看次数

在onZeroItemsLoaded之后立即调用onItemAtEndLoaded

我有一个问题,紧接着onItemAtEndLoaded调用该方法 onZeroItemsLoaded,行为应该只在我完成滚动时.你知道发生了什么吗?我可以提供我的GitHub回购.

android-jetpack android-paging

14
推荐指数
1
解决办法
480
查看次数

在Ubuntu和Perl 5.26中安装Raku(Perl 6)

我很想学习Raku(Perl 6)及其语法。

我的Ubuntu计算机上已经安装了Perl 5。

vinod@ubuntu-s-1vcpu-1gb-nyc1-01:~$ perl -v

This is perl 5, version 26, subversion 1 (v5.26.1) built for x86_64-linux-gnu-thread-multi
(with 67 registered patches, see perl -V for more detail)

Copyright 1987-2017, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc …
Run Code Online (Sandbox Code Playgroud)

perl install perl6 rakudo-star raku

8
推荐指数
2
解决办法
218
查看次数

Perl 如何使用 DBI 模块更改帐户主机?

我的公司在具有 IP 的服务器中有一个 Perl 应用程序:10.10.3.39

由于实施了新规则,我必须将数据库迁移到具有 IP 的服务器中的 MySQL DB:10.10.1.18

我公司的数据库管理员已创建一个帐户并授予用户名 : 的应用程序访问权限'user'@'10.10.3.39'。所以该帐户只能从具有IP的服务器上使用10.10.3.39

我尝试使用命令在服务器中连接mysql -h 10.10.1.18 -u user -p

[hanief@dev39 project]$ mysql -h 10.10.1.18 -u user -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 19484169
Server version: 10.0.15-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current …
Run Code Online (Sandbox Code Playgroud)

mysql perl dbi mariadb

6
推荐指数
1
解决办法
329
查看次数

为什么我们使用Catalyst的Context对象?它的目的是什么?

我以为我真的不明白为什么催化剂中的所有东西都使用了上下文对象.似乎一切都从一开始

my ( $self, $c ) = @_;
Run Code Online (Sandbox Code Playgroud)

我们用催化剂模型包装DBIC并最终得到

$c->model('DBIC::Table') ...
Run Code Online (Sandbox Code Playgroud)

或许我们这样做

$c->log->warn('foo');
Run Code Online (Sandbox Code Playgroud)

但我不明白为什么我们不这样做

log('warn', 'foo'); # or whatever the API for some log library is.
Run Code Online (Sandbox Code Playgroud)

为什么我们通过上下文对象做所有事情?是什么让它与众不同?

perl catalyst

5
推荐指数
1
解决办法
1434
查看次数

perl打开文件名中包含变量的文件

我尝试打开文件夹中的文件列表.最后我想在其中插入一个HTML-Snippet.到目前为止,我可以打开文件夹并读取数组中的列表.没关系.但是当我尝试使用变量作为文件名打开文件时,我每次都会收到一条错误消息("权限被拒绝").无论我使用$ _还是将列表项的值放在变量中的其他变体.我在这里找到了类似的问题,但到目前为止还没有找到解决方案.这是我的代码:

use strict;
use warnings;

my ($line);

opendir (FOLDER,"path/to/folder/./") or die "$!";
my @folderlist = readdir(FOLDER);
my @sorted_folderlist = sort @folderlist;
close(FOLDER);

foreach (@sorted_folderlist) {
  my $filename = $_;
  open (READ, ">", "path/to/folder/$filename") or die "$!";
  # do something
  close (READ);
}
Run Code Online (Sandbox Code Playgroud)

这里有什么错误?我如何使用变量作为文件名打开文件?

Pjoern

这是我改变的代码,以回答1:

my $dh; 
opendir $dh, "dir/./" or die ... 
my @folderlist = grep { -f "dir/$_" } readdir $dh; 
close $dh; 
my @sorted_folderlist = sort @folderlist; 

foreach my $filename (@sorted_folderlist) { 
  open my $fh, "<", …
Run Code Online (Sandbox Code Playgroud)

arrays perl file

5
推荐指数
2
解决办法
752
查看次数

UTF-8编码的JSON文件,尝试使用JSON模块解析 - 宽字符

我有一个非常简单的 Perl 脚本:

use JSON;

use open qw/ :std :encoding(utf8) /;

#my $ref = JSON::decode_json($json_contents);

my $path = "/home/chambres/web/x.org/public_html/cgi-bin/links/admin/booking_import/import/file.json";

my $json_contents = slurp_utf8_file($path);

my $ref =  JSON->new->utf8->decode($json_contents);

sub slurp_utf8_file {

  my @back;
  #open my $in,  '<:encoding(UTF-8)',  $_[0]  or die $!;
  open my $in,  "<$_[0]" or die $!;
    while (<$in>) {
      push @back, $_
    }
  close ($in);

  return join("", @back);
}
Run Code Online (Sandbox Code Playgroud)

该文件在 Notepad++ 中以 UTF-8 编码:

在此输入图像描述

...但是当我运行脚本时我得到:

perl test.cgi
Wide character in subroutine entry at test.cgi line 11.
Run Code Online (Sandbox Code Playgroud)

11号线是:

my $ref …
Run Code Online (Sandbox Code Playgroud)

perl utf-8

5
推荐指数
1
解决办法
2153
查看次数

读取CSV文件并保存为2 d阵列

我试图在二维数组中读取一个巨大的CSV文件,必须有一个更好的方法来分割线并一步保存在二维数组中:s干杯

my $j = 0;
while (<IN>) 
{

    chomp ;
    my @cols=();
    @cols   = split(/,/); 
    shift(@cols) ; #to remove the first number which is a line header
    for(my $i=0; $i<11; $i++) 
    {
       $array[$i][$j]  = $cols[$i];
    }        
    $j++;    
}
Run Code Online (Sandbox Code Playgroud)

arrays perl

4
推荐指数
2
解决办法
1万
查看次数

如何在其他列之间插入列 (Perl Spreadsheet::WriteExcel)

假设我有以下电子表格,可以在 perl 中解析,如下所示:

在此输入图像描述

我想在 Column1 和 Column2 之间插入一列。所以最终结果如下所示:

在此输入图像描述

Spreadsheet-WriteExcel 中似乎没有为此设置方法。

有谁知道在 Perl 中执行此操作的简单方法吗?

提前谢谢了!

excel perl spreadsheet

4
推荐指数
1
解决办法
1216
查看次数

如何将字符串转换为perl中的文件句柄?

我有一个非常大的字符串$s="dfasdfasdfafd....",有近1,000,000个字符.我想将其转换为文件句柄,使其看起来像从文件中读取此字符串.但我不想将它存储到临时文件中并阅读它.

谁能给我一些建议?

string perl filehandle

4
推荐指数
1
解决办法
2625
查看次数