perl

How do I use an index in an array reference as a method reference in Perl?

◇◆丶佛笑我妖孽 提交于 2020-02-02 02:45:26
问题 Similar to this question about iterating over subroutine references, and as a result of answering this question about a OO dispatch table, I was wondering how to call a method reference inside a reference, without removing it first, or if it was even possible. For example: package Class::Foo; use 5.012; #Yay autostrict! use warnings; # a basic constructor for illustration purposes.... sub new { my $class = shift; return bless {@_}, $class; } # some subroutines for flavor... sub sub1 { say 'in

Linux下使用tail查找日志文件关键词有颜色、高亮显示

為{幸葍}努か 提交于 2020-02-01 08:46:59
https://blog.csdn.net/qq_27686779/article/details/81180254 tail -f 日志文件 | perl -pe 's/(关键词)/\e[特效;(背景色);颜色m$1\e[0m/g' 注:关键词是括号符号,背景色位置括号表示可省 例:单个关键词高亮 tail -f catalina.out | perl -pe 's/(DEBUG)/\e[1;34m$1\e[0m/g' 多个关键词高亮 tail -f catalina.out | perl -pe 's/(关键词1)|(关键词2)|(关键词3)/\e[1;颜色1$1\e[0m\e[1;颜色2$2\e[0m\e[1;颜色3$3\e[0m/g' tail -f catalina.out | perl -pe 's/(DEBUG)|(INFO)|(ERROR)/\e[1;34m$1\e[0m\e[1;33m$2\e[0m\e[1;31m$3\e[0m/g' 备注: 匹配关键词使用的是正则表达式 字体颜色设置: 30:黑 31:红 32:绿 33:黄 34:蓝 35:紫 36:青 37:白 背景颜色设置:40-47 黑、红、绿、黄、蓝、紫、青、白 40:黑 41:红 42:绿 43:黄 44:蓝 45:紫 46:青 47:白 其他参数说明 1 设置高亮加粗 4 下划线 5 闪烁 例子:

Perl Image::OCR::Tesseract module on Windows

前提是你 提交于 2020-02-01 05:48:12
问题 Anyone out there know of a graceful way to install the "Image::OCR::Tesseract" module on Windows? The module fails to install on Windows via CPAN due to a *NIX only module dependency called "LEOCHARRE::CLI". This module does not seem to be required to run "Image::OCR::Tesseract" itself. I've managed to get the module working by first manually installing the dependency modules listed in the makefile.pl (except for "LEOCHARRE::CLI") and then by moving the module file to the correct directory

“ppm.bat install failed: Can't find any package that provides MinGW”

元气小坏坏 提交于 2020-02-01 04:56:05
问题 I am trying to install a missing Perl module (Palm::PDB) in Windows 7. I have tried the following: Using Perl Package Manager: unfortunately it does not seem to find the module I want. Starting a CPAN shell in Windows using the command prompt: unfortunately it shows the following error. I have installed MinGW and also have set the path. D:\Scripts>perl -MCPAN -e 'shell' install Palm::PDB It looks like you don't have a C compiler and make utility installed. Trying to install dmake and the

How can Install multiple Perl versions without them tripping over each other's XS modules?

我的未来我决定 提交于 2020-02-01 03:43:07
问题 I would like to install several different versions of perl in my home directory. I tried using App::perlbrew, but XS modules from one version were causing segfaults in the other version. Is there any way to install multiple versions of perl and have them automatically keep their XS modules separate? 回答1: You can install each perl completely separate from any other perl installation. It's binaries and modules will be completely separate from each other. Essentially, when you install each perl

简单描述PHP发展历程

不想你离开。 提交于 2020-02-01 00:43:42
PHP简介 PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,利于学习,使用广泛,主要适用于Web开发领域。PHP 独特的语法混合了C、Java、Perl以及PHP自创的语法。它可以比CGI或者Perl更快速地执行动态网页。用PHP做出的动态页面与其他的编程语言相比,PHP是将程序嵌入到HTML(标准通用标记语言下的一个应用)文档中去执行,执行效率比完全生成HTML标记的CGI要高许多;PHP还可以执行编译后代码,编译可以达到加密和优化代码运行,使代码运行更快。 PHP是通用服务器端脚本编程语言,其主要用于web开发以实现动态web页面,它也是最早实现将脚本嵌入HTML源码文档中的服务器端脚本语言之一。同时,php还提供了一个命令行接口,因此,其也可以在大多数系统上作为一个独立的shell来使用。Rasmus Lerdorf于1994年开始开发PHP,它是初是一组被Rasmus Lerdorf称作“Personal Home Page Tool”的Perl脚本,这些脚本可以用于显示作者的简历并记录用户对其网站的访问。后来,Rasmus Lerdorf使用C语言将这些Perl脚本重写为CGI程序,还为其增加了运行Web forms的能力以及与数据库交互的特性

How do I convert an array to a hash in Perl?

╄→гoц情女王★ 提交于 2020-01-31 06:59:13
问题 I have an array and tried to convert the array contents to a hash with keys and values. Index 0 is a key, index 1 is a value, index 2 is a key, index 3 is a value, etc. But it is not producing the expected result. The code is below: open (FILE, "message.xml") || die "Cannot open\n"; $var = <FILE>; while ($var ne "") { chomp ($var); @temp = split (/[\s\t]\s*/,$var); push(@array,@temp); $var = <FILE>; } $i = 0; $num = @array; while ($i < $num) { if (($array[$i] =~ /^\w+/i) || ($array[$i] =~ /\d

Calling a Perl module from Python

会有一股神秘感。 提交于 2020-01-31 03:27:25
问题 my question is the inverse of this one. In particular, I've dozens of existing modules written in Perl, some are object oriented and others just export a group of functions. Now since I have to write certain scripts in python but still would like to call those Perl modules, I'm wondering 1) if it is achievable, and 2) if so, what would be the best way of doing it Ideally, the Perl modules would appear as "black boxes" to Python, so to speak. Something like: from perl_module import * return

Perl语言中的ig

a 夏天 提交于 2020-01-30 22:12:55
Perl 中s/// 和 tr/// 的差别 说真的,要学好 perl 还真的不简单, 因为 perl 的程序代码比C来得精简一半1,靠得就是在撰写时的大脑运作。程设师得花更多时间写出精简的 code,同时也要将「语意上的错误」减少到最低,这就是要靠经验的累积 。废话不多说,先说s/// 置换的功能,s 是 substitute的意思: s/原来字符串/目的字符串/修饰子 s/// 会默认搜索 $ _,找出「原来字符串」,换成「目的字符串」。该运算符返回匹配的数量或进行替换的数量,如果没有进行任何匹配,则返回0。 ex: 把 Who 换成 What $str = "Who are you?"; $str =~ s/Who/What/; 要取得比对成功的个数,可以写 print $str =~ s/Who/What/; # 结果 1 但是 print $str; What are you? 很有趣的差别,就算是老手也容易忘记,其实写成这样就容易种了 $cnt= ($str =~ s/Who/What/); #$cnt=1 s/// 只会预设置换第一个找到的目标字符串,假若想全部置换,就要加 g 修饰子: $str = "What a wonderful wonderful world."; $str =~ s/w/W/g; # str = "What a Wonderful

Select a particular column using awk or cut or perl

纵饮孤独 提交于 2020-01-30 19:58:09
问题 I have a requirement to select the 7th column from a tab delimited file. eg: cat filename | awk '{print $7}' The issue is that the data in the 4th column has multiple values with blank in between. example - The last line in the below output: user \Adminis FL_vol Design 0 - 1 - group 0 FL_vol Design 19324481 - 3014 - user \MAK FL_vol Design 16875161 - 2618 - tree 826 FL_vol Out Global Doc Mark 16875162 - 9618 - /vol/FL_vol/Out Global Doc Mark 回答1: If the data is unambiguously tab-separated,