perl

How do I match across newlines in a perl regex?

不问归期 提交于 2020-11-29 08:35:00
问题 I'm trying to work out how to match across newlines with perl (from the shell). following: (echo a b c d e; echo f g h i j; echo l m n o p) | perl -pe 's/(c.*)/[$1]/' I get this: a b [c d e] f g h i j l m n o p Which is what I expect. But when I place an /s at the end of my regex, I get this: a b [c d e ]f g h i j l m n o p What I expect and want it to print is this: a b [c d e f g h i j l m n o p ] Is the problem with my regex somehow, or my perl invocation flags? 回答1: -p loops over input

Read-write lock in Perl

浪尽此生 提交于 2020-11-29 08:31:08
问题 I am looking for a good way to implement read/write lock in Perl. This is needed to synchronize file access from different Perl threads and/or processes on Windows and Unix. Tried Fcntl::flock which would be perfect for me if it worked as expected. Unfortunately it looks like under stress flock allows to set lock on already locked file in another thread. Looked into some CPAN modules, but most are implemented with flock. Next I am planning to evaluate fcntl for Unix and Win32::Mutex for

Read-write lock in Perl

不羁的心 提交于 2020-11-29 08:30:07
问题 I am looking for a good way to implement read/write lock in Perl. This is needed to synchronize file access from different Perl threads and/or processes on Windows and Unix. Tried Fcntl::flock which would be perfect for me if it worked as expected. Unfortunately it looks like under stress flock allows to set lock on already locked file in another thread. Looked into some CPAN modules, but most are implemented with flock. Next I am planning to evaluate fcntl for Unix and Win32::Mutex for

Why is this A0 character appearing in my HTML::Element output?

匆匆过客 提交于 2020-11-28 03:45:41
问题 I'm parsing an HTML document with a couple Perl modules: HTML::TreeBuilder and HTML::Element. For some reason whenever the content of a tag is just   , which is to be expected, it gets returned by HTML::Element as a strange character I've never seen before: alt text http://www.freeimagehosting.net/uploads/2acca201ab.jpg I can't copy the character so can't Google it, couldn't find it in character map, and strangely when I search with a regular expression, \w finds it. When I convert the

Why is this A0 character appearing in my HTML::Element output?

巧了我就是萌 提交于 2020-11-28 03:43:19
问题 I'm parsing an HTML document with a couple Perl modules: HTML::TreeBuilder and HTML::Element. For some reason whenever the content of a tag is just   , which is to be expected, it gets returned by HTML::Element as a strange character I've never seen before: alt text http://www.freeimagehosting.net/uploads/2acca201ab.jpg I can't copy the character so can't Google it, couldn't find it in character map, and strangely when I search with a regular expression, \w finds it. When I convert the

Why is this A0 character appearing in my HTML::Element output?

瘦欲@ 提交于 2020-11-28 03:42:30
问题 I'm parsing an HTML document with a couple Perl modules: HTML::TreeBuilder and HTML::Element. For some reason whenever the content of a tag is just   , which is to be expected, it gets returned by HTML::Element as a strange character I've never seen before: alt text http://www.freeimagehosting.net/uploads/2acca201ab.jpg I can't copy the character so can't Google it, couldn't find it in character map, and strangely when I search with a regular expression, \w finds it. When I convert the

Why is this A0 character appearing in my HTML::Element output?

本小妞迷上赌 提交于 2020-11-28 03:41:04
问题 I'm parsing an HTML document with a couple Perl modules: HTML::TreeBuilder and HTML::Element. For some reason whenever the content of a tag is just   , which is to be expected, it gets returned by HTML::Element as a strange character I've never seen before: alt text http://www.freeimagehosting.net/uploads/2acca201ab.jpg I can't copy the character so can't Google it, couldn't find it in character map, and strangely when I search with a regular expression, \w finds it. When I convert the

Linux文本文件——文本编辑器Vim

血红的双手。 提交于 2020-11-27 05:48:05
Linux文本文件——文本编辑器Vim 摘要:本文主要学习在Linux系统中使用Vim文本编辑器编辑文本。 什么是Vim Vim是一个基于文本界面的编辑工具,使用简单且功能强大。更重要的是,Vim是所有Linux发行版本默认的文本编辑器。 很多人习惯将Vim称为Vi,其实Vim是Vi的增强版(在Vi的基础上增加了正则表达式的查找、多窗口的编辑等功能),使用Vim进行程序开发会更加方便。 安装Vim文本编辑器 众多Linux发行版系统,通常都已经默认安装好了Vi或Vim文本编辑器,Centos也不例外,该系统就默认安装有Vi文本编辑器,但建议大家使用Vim。 查看是否安装了Vim文本编辑器 在命令行模式下输入“vim”,输出结果为“Command not found”,或者是“未找到命令”,则表示此系统中未安装Vim: 1 [root@localhost ~ ]# vim 2 - bash: vim: 未找到命令 3 [root@localhost ~]# 说明没有安装Vim。 安装Vim文本编辑器 CentOS系统中,使用如下命令即可安装Vim: 1 yum install -y vim 安装过程如下: 1 已安装: 2 vim-enhanced.x86_64 2 : 7.4 . 160 - 6 .el7_6 3 4 作为依赖被安装: 5 gpm-libs.x86_64 0 : 1

Accessing shell variable in a Perl program

一曲冷凌霜 提交于 2020-11-24 17:25:27
问题 I have this Perl script: #!/usr/bin/perl $var = `ls -l \$ddd` ; print $var, "\n"; And ddd is a shell variable $ echo "$ddd" arraytest.pl When I execute the Perl script I get a listing of all files in the directory instead of just one file, whose file name is contained in shell variable $ddd. Whats happening here ? Note that I am escaping $ddd in backticks in the Perl script. 回答1: The variable $ddd isn't set *in the shell that you invoke from your Perl script. Ordinary shell variables are not

Accessing shell variable in a Perl program

[亡魂溺海] 提交于 2020-11-24 17:19:13
问题 I have this Perl script: #!/usr/bin/perl $var = `ls -l \$ddd` ; print $var, "\n"; And ddd is a shell variable $ echo "$ddd" arraytest.pl When I execute the Perl script I get a listing of all files in the directory instead of just one file, whose file name is contained in shell variable $ddd. Whats happening here ? Note that I am escaping $ddd in backticks in the Perl script. 回答1: The variable $ddd isn't set *in the shell that you invoke from your Perl script. Ordinary shell variables are not