perl

Why does Perl's glob() function always return a file name when given a string with no globbing characters?

一笑奈何 提交于 2020-07-20 07:15:46
问题 I gave a list of globs and one string to Perl's glob function. The globs were treated as expected but the string is always found. For example: $ ls foo $ perl -le '@files=glob("*bar"); print @files' ## prints nothing, as expected $ perl -le '@files=glob("bar"); print @files' bar As you can see above, the second example prints bar even though no such file exists. My first thought is that it behaves like the shell in that when no expansion is available, a glob (or something being treated as a

Why does Perl's glob() function always return a file name when given a string with no globbing characters?

三世轮回 提交于 2020-07-20 07:15:13
问题 I gave a list of globs and one string to Perl's glob function. The globs were treated as expected but the string is always found. For example: $ ls foo $ perl -le '@files=glob("*bar"); print @files' ## prints nothing, as expected $ perl -le '@files=glob("bar"); print @files' bar As you can see above, the second example prints bar even though no such file exists. My first thought is that it behaves like the shell in that when no expansion is available, a glob (or something being treated as a

Where does CPAN install modules?

早过忘川 提交于 2020-07-20 07:07:01
问题 I can't find an authoritative/comprehensive description of where CPAN installs its files. I assume there must be a set of rules and that it's not as simple as "XYZ directory" because, for example, multiple users on a Linux box can run CPAN even though there's a single Perl installation and it still somehow works. So, what are those rules? A second part of this question: The documentation for the PERL5LIB environment variable says that it is "A list of directories in which to look for Perl

Where does CPAN install modules?

左心房为你撑大大i 提交于 2020-07-20 07:05:06
问题 I can't find an authoritative/comprehensive description of where CPAN installs its files. I assume there must be a set of rules and that it's not as simple as "XYZ directory" because, for example, multiple users on a Linux box can run CPAN even though there's a single Perl installation and it still somehow works. So, what are those rules? A second part of this question: The documentation for the PERL5LIB environment variable says that it is "A list of directories in which to look for Perl

How to use “here-doc” to print lines to file?

淺唱寂寞╮ 提交于 2020-07-18 18:06:17
问题 Basically this is the result of my programming on google for last half an hour trying to achieve a simple thing: pick up user inputs from STDIN and write them into a structured XML file as the output, below is my ugly code: #!/bin/perl print "img URL = ? "; $img = <>; chomp($img); print "filename = ? "; $filename = <>; chomp($filename); # now write xml with inserted contents to a file: open (CARDFILE, ">>$filename"); print CARDFILE "<card>\r\n"; print CARDFILE " <img>$img</img>\r\n"; print

How can I get a only part of a hash in Perl?

心不动则不痛 提交于 2020-07-17 06:16:11
问题 Is there a way to get a sub-hash? Do I need to use a hash slice? For example: %hash = ( a => 1, b => 2, c => 3 ); I want only %hash = ( a => 1, b => 2 ); 回答1: Hash slices return the values associated with a list of keys. To get a hash slice you change the sigil to @ and provide a list of keys (in this case "a" and "b" ): my @items = @hash{"a", "b"}; Often you can use a quote word operator to produce the list: my @items = @hash{qw/a b/}; You can also assign to a hash slice, so if you want a

Cannot access selenium server on localhost from Perl using LWP::UserAgent on Windows 10, Strawberry Perl

南楼画角 提交于 2020-07-16 04:28:08
问题 On Windows 10, I installed geckodriver.exe from https://github.com/mozilla/geckodriver/releases and Selenium Server from https://www.selenium.dev/downloads/ I started the server successfully from the command prompt: > java "-Dwebdriver.gecko.driver=geckodriver/geckodriver.exe" -jar selenium-server/selenium-server-standalone-3.141.59.jar -host localhost -port 4444 20:00:48.591 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358 20:00:53.896 INFO

Cannot access selenium server on localhost from Perl using LWP::UserAgent on Windows 10, Strawberry Perl

三世轮回 提交于 2020-07-16 04:24:59
问题 On Windows 10, I installed geckodriver.exe from https://github.com/mozilla/geckodriver/releases and Selenium Server from https://www.selenium.dev/downloads/ I started the server successfully from the command prompt: > java "-Dwebdriver.gecko.driver=geckodriver/geckodriver.exe" -jar selenium-server/selenium-server-standalone-3.141.59.jar -host localhost -port 4444 20:00:48.591 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358 20:00:53.896 INFO

Why is Perl regex \K not excluding the pattern matched before \K?

社会主义新天地 提交于 2020-07-16 04:19:22
问题 I have a file called test.txt with the following: > Last login: Mon Jul 13 05:09:33 2020 You have mail. > ****************************** > cat, you have just logged into machine sampleserver2 > ****************************** > > -------------------------------------------------------------- > | To switch environments later, run: | > | | > | change | > | | > -------------------------------------------------------------- > > > Current Dir => /apps/users/cat Oracle SID: SAMPLE > cat

Is there a way to create an executable that runs both Python and Perl script?

荒凉一梦 提交于 2020-07-10 07:20:49
问题 I'm building a Python program that also runs a Perl script from within. Is there a way to create an executable where the user of my program doesn't have to install Perl but has Python? 回答1: Here is an example of how you can use pp to build an executable (that does not depend on the perl executable being installed). I am using perlbrew with perl version 5.30 on Ubuntu 20.04. First install pp : cpanm PAR::Packer Create a test Perl script hello.pl (you may need to install Path::Tiny first): use