perl

Change the width of all lines in a PDF programmatically

你。 提交于 2021-01-27 15:23:57
问题 I made handwritten slides using an iPad app, and found out that the line was too thin to be projected on a big screen in a room. Unfortunately that app doesn't have the ability to change the stroke widths afterwards... (geez.) But I have the exported PDF file. As a programmer I should be able to solve my problem programmatically, by changing the width of all lines on a PDF by, say, a factor of two. So, my question is what would be the easiest way to achieve my objective. Is there a Perl

How can I convert text to title case?

早过忘川 提交于 2021-01-27 13:17:02
问题 I have a text file containing a list of titles that I need to change to title case (words should begin with a capital letter except for most articles, conjunctions, and prepositions). For example, this list of book titles: barbarians at the gate hot, flat, and crowded A DAY LATE AND A DOLLAR SHORT THE HITCHHIKER'S GUIDE TO THE GALAXY should be changed to: Barbarians at the Gate Hot, Flat, and Crowded A Day Late and a Dollar Short The Hitchhiker's Guide to the Galaxy I wrote the following code

Dynamically creating an associative array of arrays

こ雲淡風輕ζ 提交于 2021-01-27 11:38:49
问题 I'm trying to dynamically create an associative array whose values are arrays. My current attempt is as follows but I'm not sure if it is correct or efficent. foreach $line (@lines) # read line from a text dictionary { chomp( $line ); my($word, $definition) = split(/\s/, $line, 2); # $definition =~ s/^\s+|\s+$//g ; # trim leading and trailing whitespace if( exists $dict{$word} ) { @array = $dict{$word}; $len = scalar @array; $dict{$word}[$len] = $definition; } else { $dict{$word}[0] =

Dynamically creating an associative array of arrays

拈花ヽ惹草 提交于 2021-01-27 11:38:07
问题 I'm trying to dynamically create an associative array whose values are arrays. My current attempt is as follows but I'm not sure if it is correct or efficent. foreach $line (@lines) # read line from a text dictionary { chomp( $line ); my($word, $definition) = split(/\s/, $line, 2); # $definition =~ s/^\s+|\s+$//g ; # trim leading and trailing whitespace if( exists $dict{$word} ) { @array = $dict{$word}; $len = scalar @array; $dict{$word}[$len] = $definition; } else { $dict{$word}[0] =

Why is the STDOUT line printed after the STDERR line?

て烟熏妆下的殇ゞ 提交于 2021-01-27 07:22:23
问题 I completly don't understand this behaviour. I have a very simple Perl script: #!/usr/bin/perl use strict; use warnings; print "line 1\n"; print STDERR "line 2\n"; If I run it from console I will get what I expect: $ perl a.pl line 1 line 2 But if I redirect it to file, I will get the lines in the reverse order: $ perl a.pl &> a $ cat a line 2 line 1 How can I capture all the outputs STDOUT+STDERR to the file with the same order I get in the console? 回答1: This is an effect of buffering. When

Capture word between optional hyphens regex

半腔热情 提交于 2021-01-27 07:13:35
问题 I've following type of strings, abc - xyz abc - pqr - xyz abc - - xyz abc - pqr uvw - xyz I want to retrieve the text xyz from 1st string and pqr from 2nd string, `` (empty) from 3rd & pqr uvw . The 2nd hyphen is optional. abc is static string, it has to be there. I've tried following regex, /^(?:abc) - (.*)[^ -]?/ But it gives me following output, xyz pqr - xyz - xyz pqr uvw - xyz I don't need the last part in the second string. I'm using perl for scripting. Can it be done via regex? 回答1:

batch renaming of files with perl expressions

僤鯓⒐⒋嵵緔 提交于 2021-01-27 05:27:59
问题 This should be a basic question for a lot of people, but I am a biologist with no programming background, so please excuse my question. What I am trying to do is rename about 100,000 gzipped data files that have existing name of a code (example: XG453834.fasta.gz). I'd like to name them to something easily readable and parseable by me (example: Xanthomonas_galactus_str_453.fasta.gz). I've tried to use sed , rename , and mmv , to no avail. If I use any of those commands on a one-off script

batch renaming of files with perl expressions

纵然是瞬间 提交于 2021-01-27 05:27:27
问题 This should be a basic question for a lot of people, but I am a biologist with no programming background, so please excuse my question. What I am trying to do is rename about 100,000 gzipped data files that have existing name of a code (example: XG453834.fasta.gz). I'd like to name them to something easily readable and parseable by me (example: Xanthomonas_galactus_str_453.fasta.gz). I've tried to use sed , rename , and mmv , to no avail. If I use any of those commands on a one-off script

URL静态化与搜索引擎的关系?

偶尔善良 提交于 2021-01-26 20:30:33
网站有静态页面和动态页面之分。 静态URL又称为静态页面,是一个固定的网址,不包含任何参数或代码,通常以“.html”“.htm”“.xml”“.shtml”为后缀的结尾。动态URL又称为动态页面,通常以“.asps”“.asp”“.jsp”“. php ”“.perl”“.cgi”等后缀结尾,在页面的URL中也会包含一些特殊符号,例如:“?”“&”“=”等等。 如今很多网站的功能都是通过数据库来实现的,页面由程序生成,而不是在服务器上以静态文件出现。很早以前,搜索引擎是无法抓取动态页面的内容,虽然现在抓取技术的不断提高,但是动态页面可能会产生无限循环和大量的重复页面,这样会降低搜索引擎造的好感度,容易删除百度信息。 1、无限循环动态页面 例如:飞机订票网站,提供根据时间查询机票信息的功能,网站在编写程序的时候,会使用万年历功能,如果搜索引擎一直跟踪上面的链接,就会不停的抓取下一个页面,从而陷入无尽的循环中,就像百度镜像一样,而每个页面并没有实际的变化,这样就会影响搜索引擎的抓取效率。 2、重复动态页面 重复动态页面是指相同的内容对应不同的动态链接。动态页面会产生重复页面链接,而搜索引擎对于这种情况也会重复抓取,这样会造成搜索引擎的资源浪费。如果是静态页面,就不会产生重复页面。 什么是URL静态化?就是通过技术手段将动态URL重写成静态URL,经过重写后,没有改变原来的页面内容

How can I run a perl script from R with specific modules?

给你一囗甜甜゛ 提交于 2021-01-24 07:16:17
问题 I can run a perl script "myperlscript.pl" from Terminal without any problems. However, if I try to run the same perl script from within RStudio, it gives me the following error: command <- "myperlscript.pl outputfile.txt" system2('perl', command) Can't locate Sort/Fields.pm in @INC (you may need to install the Sort::Fields module) (@INC contains: /Library/Perl/5.28/darwin-thread-multi-2level /Library/Perl/5.28 /Network/Library/Perl/5.28/darwin-thread-multi-2level /Network/Library/Perl/5.28